【发布时间】:2014-11-23 05:46:47
【问题描述】:
单击我的TreeView 的任何节点都不会选择它。我需要单击节点左侧的一个小矩形区域(在图像中显示为红色)以选择它。此外,以这种方式选择节点意味着将立即选择具有所有子节点的整个子树。不知道发生了什么。
这是我的 XAML:
<TreeView ItemsSource="{Binding FirstGeneration}">
<TreeView.Resources>
<DataTemplate DataType="{x:Type local:AccountNodeVM}">
<TreeViewItem Header ="{Binding Name}" />
</DataTemplate>
<HierarchicalDataTemplate DataType="{x:Type local:CategoryNodeVM}" ItemsSource="{Binding SubCategories}">
<TreeViewItem Header="{Binding Name}" ItemsSource="{Binding Accounts}" />
</HierarchicalDataTemplate>
</TreeView.Resources>
<TreeView.ItemContainerStyle>
<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>
</TreeView.ItemContainerStyle>
</TreeView>
FirstGeneration、SubCategories、Accounts 都在我的 ViewModel 中定义。我也尝试在我的HierarchicalDataTemplate 中使用TextBlock 而不是TreeViewItem,但没有任何收获。我在这里做错了什么?
【问题讨论】: