If I have this structure:
public class Parent { public string Name{get; set;} public List<Child> Childs {get; set;} } public class Child { public string Name{get; set;} public string Value{get; set;} public enum ValueType {get; set;} } public enum ValueType { Int, Boolean, String }; public class ParentFactory { public List<Parent> Parents {get; set;} public ParentFactory() { Child child1 = new Child() {Name="Filter1", Value="1", ValueType=ValueType.String}; Child child2 = new Child() {Name="isExecuted", Value="true", ValueType=ValueType.Boolean}; Child child3 = new Child() {Name="Width", Value="10", ValueType=ValueType.Int}; Parent parent1 = new Parent(){Name="Adam", Childs = new List<Child>(){child1, child2}}; Parent parent2 = new Parent(){Name="Kevin", Childs = new List<Child>(){child3}}; Parents = new List<Parent>(){parent1, parent2}; } }
I want to bind an object: ParentFactory parentFactory = new ParentFactory()
to ItemsControl:
<DockPanel> <ItemsControl ItemsSource="{Binding Parents}"> </ItemsControl> </DockPanel> <Window.Resources> <DataTemplate DataType="{x:Type Parent}"> <StackPanel Margin="2,2,2,1"> <Expander Header="{Binding Name}"> <ItemsControl ItemsSource="{Binding Childs}" /> </Expander> </StackPanel> </DataTemplate> <DataTemplate DataType="{x:Type Child}"> <StackPanel> <TextBox Grid.Column="0" Text="{Binding Name}" /> <TextBox Grid.Column="1" Text="{Binding Value}"/> <TextBox Grid.Column="2" Text="{Binding ValueType}"/> </StackPanel> </DataTemplate> </Window.Resources>
Stackpanel has one control: TextBox. However, I want it to be more dynamic: if ValueType is logical, then use the checkbox, and then use the text box for: <TextBox Grid.Column="1" Text="{Binding Value}"/>
.
Is this possible, and if so, how can I achieve it?
source share