在List我存储了几个带有标题和子项目的项目
_categories = new List<Category>();
Category cOne = new Category() { Header = "Category one" };
cOne.AddItem("Sub One");
cOne.AddItem("Sub Two");
cOne.AddItem("Sub Three");
_categories.Add(cOne);
在 WPF 中,我将这些项目绑定到一个ListBox.
<ListBox x:Name="listbox">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Header}" />
<ListBox ItemsSource="{Binding Subs}" Padding="10 0 0 0" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
我现在尝试但失败的是只制作内部ListBox可点击的项目,即避免:

如果我设置TextBlock.IsEnabled或设置TextBlock.IsHitTestVisible为 false,则没有任何变化。如果StackPanel's属性设置为 false,则内部ListBox不再是可点击的,但有趣的是TextBlock仍然是。并且外部ListBox's属性根本阻止单击任何内容。
如果外部ListBox是 a ,则行为是相同的ListView。
我还没有弄清楚我需要更改什么以确保仅启用内部列表中的项目。有任何想法吗?