Dynamically adding a UserControl to a ListBox
Posted: 24 Sep 2014, 21:27
What is the best way to add multiple different UserControls to a ListBox at runtime? Do I need to always use a DataModel when adding lines to a ListBox? Here are some options that I can think of:
1. Tie each unique UserControl to a DataTemplate. I don't think this approach is possible because the DataModel approach assumes each item uses the same DataTemplate.
2. Add UserControls to a ListBox without using a DataModel or DataTemplate.
3. I could ditch the ListBox entirely and use a StackPanel, but I would like to have a scroll capability, so I don't think that approach will work.
4. Is there a way to apply different styles to separate ListBox items?
Here are the requirements that I am attempting to satisfy:
1. The list shall have the capability of displaying different GUI elements on each line
2. The GUI elements may vary in size
3. The list shall be editable at runtime
4. The list shall be scrollable
1. Tie each unique UserControl to a DataTemplate. I don't think this approach is possible because the DataModel approach assumes each item uses the same DataTemplate.
2. Add UserControls to a ListBox without using a DataModel or DataTemplate.
3. I could ditch the ListBox entirely and use a StackPanel, but I would like to have a scroll capability, so I don't think that approach will work.
4. Is there a way to apply different styles to separate ListBox items?
Here are the requirements that I am attempting to satisfy:
1. The list shall have the capability of displaying different GUI elements on each line
2. The GUI elements may vary in size
3. The list shall be editable at runtime
4. The list shall be scrollable