Is there any way in WPF to get the same functionality as a DataTemplateSelector , but for UserControls?
Say I have a StackView to which I want to bind IEnumerable objects. What I would like to do is somehow have a mapping that, for each type of object in the linked IEnumerable, looks at the type of the object and determines what UserControl will add to the StackView.
So, given the three classes:
public class House : Building{} public class Apartment : Building{} public class Tent : Building{}
where each class inherits from Building and has its own specific UserControl , I would like to set the DataContext to IEnumerable<Building> and somehow make the StackView populate its set of child elements with the UserControl type.
I would like to do this with as little code as possible. The more data binding and XAML clone ribbon, the better.
source share