SilverLight TreeView DatabindingSilverLight TreeView Databinding
Old forum URL: forums.lhotka.net/forums/t/7427.aspx
SouthSpawn posted on Sunday, August 09, 2009
I am using a TreeView Control from the SilverLight toolkit.
I have a object that has a child ReadOnlyList property.
Can someone can me some example syntax on how I can bind the parent and child objects to the TreeView.
I tried googling this, but the examples just seem to be over my head at this point.
I am pretty new to XAML.
Any help would be awesome!!!
Ash002 replied on Sunday, August 09, 2009
Hi
Code sample
xmlns:kitctrls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
....
<kitctrls:TreeView x:Name="xTreeView"
ItemsSource="{Binding Path=Model.VisibleChildren, Source={StaticResource ViewModel}}"
Height="Auto" Width="Auto" VerticalAlignment="Stretch" Loaded="xTreeView_Loaded" >
<kitctrls:TreeView.ItemTemplate>
<kitcmmn:HierarchicalDataTemplate x:Name="TreeViewTemplate" ItemsSource="{Binding Path=VisibleChildren}">
<StackPanel Orientation="Horizontal" >
<CheckBox IsChecked="{Binding Mode=TwoWay, Path=IsSelected}" Checked="CheckBox_Checked"
Unchecked="CheckBox_Checked" Loaded="Node_Loaded" />
<TextBlock Text="{Binding Path=Name}" Margin="5,0" />
</StackPanel>
</kitcmmn:HierarchicalDataTemplate>
</kitctrls:TreeView.ItemTemplate>
</kitctrls:TreeView>
Regards
Ashley
zhengokusa replied on Tuesday, August 11, 2009
May I see what's your data model look like?
my BO look like this
factory(ReadOnlyBase) -> contacts(ReadOnlyListBase)
->property1(string) |_ contact1(ReadOnlyBase)
->property2(string) |_contact2(ReadOnlyBase)
-> Products(ReadOnlyListBase)
|_product1(ReadOnlyBase)
|_product2(ReadOnlyBase)
How doI show them on the TreeView control ?
Copyright (c) Marimer LLC