C# ListBox中的ListBox-选择行为

C# ListBox中的ListBox-选择行为,c#,wpf,listbox,C#,Wpf,Listbox,在列表中我存储了几个带有标题和子项的项目 _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); 我现在尝试但失败的是仅使内部列表框中的项目成为可点

列表中
我存储了几个带有标题和子项的项目

_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);
我现在尝试但失败的是仅使内部
列表框中的项目成为可点击,即避免:

如果我将
TextBlock.IsEnabled
TextBlock.ishittevisible
设置为false,则不会发生任何更改。如果
StackPanel的
属性设置为false,则内部的
列表框
不再可以单击,但有趣的是
文本块
仍然可以单击。而外部的
列表框的
属性阻止单击任何内容

如果外部
列表框
列表视图
,则行为相同


我还没有弄清楚我需要做哪些更改来确保只启用内部列表中的项目。有什么想法吗?

如果不需要选择外部
列表框中的项目,请不要使用
列表框
-使用
项目控件

<ItemsControl x:Name="itemsControl">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <StackPanel>
                <TextBlock Text="{Binding Header}" />
                <ListBox ItemsSource="{Binding Subs}" Padding="10 0 0 0" />
            </StackPanel>
        </DataTemplate>
  </ItemsControl.ItemTemplate>
</ItemsControl >


@HighCore感谢您的评论。最后,这确实与使用IsEnabled具有相同的效果。您是否尝试过在外部列表中使用
ItemsControl
?好吧,起初我认为您是对的,但它根本不会改变任何东西。您可能是指
ItemsControl
ListView
是选择器的后代,所以它是用来选择项目的。@nikie你当然是对的。我搞砸了。谢谢你指出这一点!对自己说:三思而后行,再写一次。@nikie谢谢你的提示。
<ItemsControl x:Name="itemsControl">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <StackPanel>
                <TextBlock Text="{Binding Header}" />
                <ListBox ItemsSource="{Binding Subs}" Padding="10 0 0 0" />
            </StackPanel>
        </DataTemplate>
  </ItemsControl.ItemTemplate>
</ItemsControl >