Switch ContentPresenter of ListBoxItem Based on Selection?

Let's suppose that we have only two data types: Item1ViewModel and Item2ViewModel Therefore we need 4 data templates: 2 for the common state, 2 for the selected state DataTemplate x:Key="Template1" DataType="local:Item1ViewModel.

Let's suppose that we have only two data types: Item1ViewModel and Item2ViewModel. Therefore we need 4 data templates: 2 for the common state, 2 for the selected state. For switching the content between two templates based on different types I use the DataTemplateSelector class: public class SampleTemplateSelector:DataTemplateSelector { public DataTemplate Type1Template { get; set; } public DataTemplate Type2Template { get; set; } public override DataTemplate SelectTemplate(object item, DependencyObject container) { if (item is Item1ViewModel) return Type1Template; else if (item is Item2ViewModel) return Type2Template; return null; } } We need two instances of this selector: one for the common state and one for the selected state.

And after that you should add this code which switches two selectors: That's all, apply this ItemTemplate to your ListBox without changing the ControlTemplate.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions