WPF: Dynamically change ListBox's ItemTemplate based on ListBox Items Size?

You could use data triggers, or you could use a DataTemplateSelector Here is an article that shows the basics. And here is the MSDN on applying it to the items control (also, a listbox).

I can't speak for the exact problem or the cause, but it is because a DataTrigger is setting a template when the count is 1 and only 1. You can do 1 of 3 things to solve this problem, but only 1 I would recommend. A) Implement your own DataTrigger by deriving from System.Windows.

TriggerBase b) Use an implementation of System.Windows.Data. IValueConverter that will convert from ItemsControl.Items. Count into a DataTemplate.

Retrieve the templates by placing an element in scope of your resources as Binding. ConverterParameter, casting them to FrameWorkElement and call FrameWorkElement.FindResource(). C) This is my recommendation, write your own DataTemplateSelector to do the grunt work.

This mechanism is specifically targeted at the functionality you with you achieve. I recently wrote one that will pick a DataTemplate based on the type of the source object without requiring a DataTemplate with no x:Key set. Using Properties on the template selector, you can pass DataTemplates into the DataTemplateSelector using XAML, removing that FindResource code 'todo' list.

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