在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
假没有什么变化。如果StackPanel's
属性设置为false,则内部ListBox
不再可点击,但有趣的是TextBlock
仍然是可以点击的。而外部的ListBox's
属性阻止点击任何东西。
如果外层ListBox
改为ListView
,则行为相同。
我还没有想出什么,我需要改变,以确保只有在内部列表中的项目启用。有任何想法吗?
的评论@HighCore感谢。最后,这与使用IsEnabled具有相同的效果。 – Em1
您是否尝试过使用'ItemsControl'作为外部列表? – Niki