View containing a different relative view

I want to create a view that will contain the entered view in the area (both will have their own ViewModels).

The first view will contain some action controls (new, save, delete, download buttons) that will β€œexecute” the second view, which will contain some field controls (TextBoxes for user input).

The first presentation (and its presentation model) cannot be the real (final) type of presentation that is in it, because this type can change (for example: customer fields, product fields, user fields).

Question: how can I achieve this using MVVM correctly?

0
source share
1 answer

If I understand your question correctly, you have a view containing a shared object, and you need another template based on what a shared object is.

If in this case use ContentControl and DataTemplates

 <ContentControl Content="{Binding SomeGenericObject}"> <ContentControl.Resources> <DataTemplate DataType="{x:Type local:CustomerViewModel}"> <local:CustomerView /> </DataTemplate> <DataTemplate DataType="{x:Type local:ProductViewModel}"> <local:ProductView /> </DataTemplate> <DataTemplate DataType="{x:Type local:OrderViewModel}"> <local:OrderView /> </DataTemplate> </ContentControl.Resources> </ContentControl> 

Regarding handling common CRUD operations in a ViewModel, see my answer to your other question about using a common interface.

+2
source

Source: https://habr.com/ru/post/912694/


All Articles