Hi,
I know there are many examples on the net but I cannot figure out how to achieve what I have to do.
My classes are:
public abstract class UIProperties : System.Object { public abstract string Caption { get; } public abstract string Description { get; } } public class CMask : UIProperties { .... } public class CommandBlock : UIProperties { public CMask Mask { get; set; } } public class CButton: UIProperties { public EButtonActions ButtonAction { get; set; } public ObservableCollection<CommandBlock> ButtonChain { get; set; } }
The TreeView I want to create is:
+ CButton.Descriprion | |-- ButtonAction | |-- CommandBlock.Description | | | |-- Mask.Description | |-- CommandBlock.Description | |-- Mask.Description+ CButton.Descriprion | ...
I'm using this XAML (where Buttons is an ObservableCollection of CButton) but how can I handle the ButtonAction node and the situation when the CommandBlock::Mask is null?
<TreeView Name="tvButtons" ItemsSource="{Binding Buttons}" ><TreeView.Resources><HierarchicalDataTemplate DataType="{x:Type local:CButton}" ItemsSource="{Binding Path=ButtonChain}"><TextBlock Text="{Binding Path=Description}" /></HierarchicalDataTemplate><HierarchicalDataTemplate DataType="{x:Type local:CommandBlock}"><TextBlock Margin="2" Text="{Binding Path=Description}" /></HierarchicalDataTemplate><HierarchicalDataTemplate DataType="{x:Type local:CMask}"><TextBlock Margin="2" Text="{Binding Path=Description}" /></HierarchicalDataTemplate></TreeView.Resources></TreeView>
I cannot use code behind because this is a data template loaded at runtime into a tab control so it has no code associated.
Some suggestions?