[英]WPF ListBox selection issue
我正在用一堆自定義控件開發應用程序。 我有一個帶有ListBox的自定義控件,其中包含其他自定義控件的集合。
這是這兩個自定義控件(容器和元素)的控件模板
容器(繼承控件):
<ControlTemplate TargetType="{x:Type local:Container}">
<Border Background="LightBlue"
BorderBrush="RoyalBlue"
BorderThickness="2" CornerRadius="5">
<StackPanel>
<TextBlock TextAlignment="Center" Text="{TemplateBinding Name}" />
<ListBox ItemsSource="{TemplateBinding Items}">
</ListBox>
</StackPanel>
</Border>
</ControlTemplate>
元素(繼承ListBoxItem):
<ControlTemplate TargetType="{x:Type local:Element}">
<Border IsHitTestVisible="True" >
<TextBlock Text="{TemplateBinding ElementName}" />
</Border>
</ControlTemplate>
問題是我無法在容器列表框中選擇任何此元素(HitTest出問題)。
有什么辦法可以選擇項目嗎?
謝謝
嘗試按照下面的說明設置ListBox的ItemsTemplate,而不要使用顯式的ControlTemplate。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.