<TreeView Name="MyTreeView" VirtualizingPanel.IsVirtualizing="True" VirtualizingPanel.VirtualizationMode="Recycling">
<TreeView.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel IsItemsHost="True"/>
</ItemsPanelTemplate>
</TreeView.ItemsPanel>
<TreeView.Resources>
<DataTemplate DataType="{x:Type EntityType:MyFixedDevice}">
<TreeViewItem IsHitTestVisible="True" IsEnabled="True">
<TreeViewItem.Header>
<TextBlock Text="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource NameConverter}}"
IsHitTestVisible="True" IsEnabled="True"/>
</TreeViewItem.Header>
</TreeViewItem>
</DataTemplate>
</TreeView.Resources>
<TreeView.Items>
<TreeViewItem Header="Data Warehouse">
<TreeViewItem.Items>
<TreeViewItem Header="Platforms">
<TreeViewItem.Items>
<TreeViewItem ItemsSource="{Binding OBJS, Converter={StaticResource COBJSourceConverter}, ConverterParameter=Fixed}">
<TreeViewItem.Header>
<TextBlock Text="{Binding RelativeSource={RelativeSource Self},
Path=Parent.Items.Count,
StringFormat=Fixed Devices ({0})}">
</TextBlock>
</TreeViewItem.Header>
</TreeViewItem>
</TreeViewItem.Items>
</TreeViewItem>
</TreeViewItem.Items>
</TreeViewItem>
</TreeView.Items>
</TreeView>
为什么左键单击使用 DataTemplate 创建的 TreeViewItems 不会选择它们?如果我在代码中选择它们,为什么不能再次选择它们或取消选择它们?
TreeViewItem selectedItem = MyTreeView.SelectedItem as TreeViewItem;
if(selectedItem != null) {
selectedItem.IsSelected = false;
MyTreeView.Focus();
}
我尝试使用以下内容TreeViewItems
在TreeView
TreeViewItems
ItemsSource
DataTemplate