How to change the content of a DataTemplate depending on its input item? #16429
-
Hi my fellow Avalonians, I am having the following problem:
Changing the content of our DataTemplate by changing the visibility of its elements does not always work, since there might be controls who are invisible but nonetheless there and they could get input values from our object of type X which they can not deal with. F.e. our object of type X could have an image location as one of its fields and we have two controls (sitting inside of our template), one for displaying gifs and another for displaying all other forms of images. The one that is invisible might not be happy with a particular location string, ending f.e. with "jpeg" but expecting always "gif". This is just a simple example. Thank you very much for any suggestion ... |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
If you can split the contents of your type into multiple type using inheritance or just separate types then you can do something like this. Rather than using
|
Beta Was this translation helpful? Give feedback.
Or you can just make a custom data template. There is full docs for it here:
https://github.com/AvaloniaUI/Avalonia.Samples/tree/main/src/Avalonia.Samples/DataTemplates/IDataTemplateSample