I currently am trying to bind my business object to a treeview as the root. And its collection property as the child. [I want to achieve this via BINDING]
Something like this.
public object MyBusinessObject
{
private int _number;
private bool _isSelected;
private ObservableCollection<AnotherObject> _other = new ObservableCollection<AnotherObject>();
public int Number { get {return _number;} set {_number = value;}}
public bool IsSelected{ get {return _isSelected;} set {_isSelected= value;}}
public ObservableCollection<AnotherObject> Children { get {return _other;}}
}
I want my treeview to be represented like this:
- "CheckBox binded to IsSelected" "Text binded to Number"
- List of child binded to my "Children"
- List of child binded to my "Children"
- List of child binded to my "Children"
- "CheckBox binded to IsSelected" "Text binded to Number"
- List of child binded to my "Children"
- List of child binded to my "Children"
- List of child binded to my "Children"
I have no idea how to do this in xaml:
<TreeView x:Name="_tv" ItemsSource="{Binding Path=MyBusinessObject}" >
<TreeView.Resources>
<HierarchicalDataTemplate>
<CheckBox Content="{Binding Path=Number} IsChecked="{Binding Path=IsSelected}" />
</HierarchicalDataTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Path=Children}">
<TextBlock Text="{Binding Path=Name}" />
</HierarchicalDataTemplate>
</TreeView.Resources>
</TreeView>
I know the above is not right, but i was wondering if there is a way to do this properly.
Thanks and Regards,