Modelling a checkable treeview in the MVVM model
Posted
by Stephen Stranded
on Stack Overflow
See other posts from Stack Overflow
or by Stephen Stranded
Published on 2010-03-26T10:27:59Z
Indexed on
2010/03/26
10:33 UTC
Read the original article
Hit count: 452
Hi, I am trying to create a checkable treeview control to list hierarchical data but it does not seem to work. I used the MVVM model example used by in codeplex simplified Treeview using ViewModel but it shows nothing. Here is my code. Please help. I am a newbie to WPF and the MVVM model but i very much want to use it in an urgent application.
</UserControl.Resources>
<Grid>
<StackPanel Height="166">
<TextBlock Text="Please Display this" />
<TreeView ItemsSource="{Binding Classifications}" Height="141">
<TreeView.ItemContainerStyle>
<!-- This Style binds a TreeViewItem to a TreeViewItemViewModel. -->
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
<Setter Property="FontWeight" Value="Normal" />
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="FontWeight" Value="Bold" />
</Trigger>
</Style.Triggers>
</Style>
</TreeView.ItemContainerStyle>
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type local:PropertyTypeViewModel}"
ItemsSource="{Binding Children}">
<StackPanel Orientation="Horizontal">
<CheckBox Focusable="false" IsChecked="{Binding isSelected}"></CheckBox>
<TextBlock Text="{Binding Classification}" />
</StackPanel>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{x:Type local:PropertyViewModel}"
ItemsSource="{Binding Children}" >
<StackPanel Orientation="Horizontal">
<CheckBox Focusable="false" IsChecked="{Binding isSelected}"></CheckBox>
<TextBlock Text="{Binding PropertyName}" />
</StackPanel>
</HierarchicalDataTemplate>
<DataTemplate DataType="{x:Type local:LeaseViewModel}">
<StackPanel Orientation="Horizontal">
<CheckBox Focusable="false" IsChecked="{Binding isSelected}"></CheckBox>
<TextBlock Text="{Binding TenantName}" />
</StackPanel>
</DataTemplate>
</TreeView.Resources>
</TreeView>
</StackPanel>
</Grid>
© Stack Overflow or respective owner