Can I use a different dataset for one data type based on some creters?

I am new to wpf and now I have a problem. I have a say model class Customerand I created a DataTemplate with the property TargetTypeset to Customer. It works well. But actually, I want two different templates, as one, to simply display the record, and the other to edit in place. Is it possible to specify two different patterns for the same data type based on some creters? And I want to switch this template based on some property in the ViewModel, for example, when IsEditmode- True.

Or am I doing it wrong? Should I use styles instead?

+3
source share
2 answers

Your approach seems perfect.

You can create a DataTemplateSelector that allows you to select a data template based on arbitrary criteria from the code.

I often use them to determine which template to use based on a property of type enum.

+3
source

There are two simple ways that I can think of, of course, there are other ways based on complexity and architecture that you want to use.

  • Define the DataTemplate using the "Key" and, in particular, call it either using the StaticResource / DynamicResource binding.
  • You can have a DataTrigger inside a datatemplate that makes some parts of the template visible / collapsed based on the 'EditMode' property
+2
source

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


All Articles