I'm currently trying to associate my business object with a tree as a root. And his collection property is like a child. [I want to achieve this through BINDING]
Something like that.
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 tree view to be presented as follows:
- "CheckBox bound to IsSelected" "Text bound to Number"
- List of children attached to my "children"
- List of children attached to my "children"
- List of children attached to my "children"
- "CheckBox bound to IsSelected" "Text bound to Number"
- List of children attached to my "children"
- List of children attached to my "children"
- List of children attached to my "children"
I don't know 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 this is wrong, but I was wondering if there is a way to do it right.
Thanks and respect,
Kev84 source
share