我有一个ComboBox
,它通过更改DataTemplate
来包含一个CheckBox
,当它自己完成时工作得很好,但是当它移动到DataGrid
中时,CheckBox
是不可点击的。
工作代码:
<ComboBox ItemsSource="{Binding WrapUpHelper.WrapUps}">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<CheckBox IsChecked="{Binding IsSelected}"
Width="20" />
<TextBlock Text="{Binding FriendlyDescription}" />
</StackPanel>
<ListBox ItemsSource="{Binding WrapUps}"
Visibility="{Binding Path=IsSelected, Converter={StaticResource BooleanToVisibilityConverter}}"
BorderThickness="0"
Background="Transparent">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox IsChecked="{Binding IsSelected}"
Width="20" />
<TextBlock Text="{Binding FriendlyDescription}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
证明:
但是,当向DataGrid
添加相同的逻辑时,ComboBox
将关闭,而不是向CheckBox
添加复选标记,而不是选择任何内容。
非工作代码:
<DataGridTemplateColumn Header="Wrap up" Width="100">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding WrapUpHelper.WrapUps}">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<CheckBox IsChecked="{Binding IsSelected}"
Width="20" />
<TextBlock Text="{Binding FriendlyDescription}" />
</StackPanel>
<ListBox ItemsSource="{Binding WrapUps}"
Visibility="{Binding Path=IsSelected, Converter={StaticResource BooleanToVisibilityConverter}}"
BorderThickness="0"
Background="Transparent">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox IsChecked="{Binding IsSelected}" Width="20" />
<TextBlock Text="{Binding FriendlyDescription}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
发布于 2017-02-07 23:57:40
当你有一个嵌套的控件,它的父控件通常会劫持HitTestVisibility,你可以冒泡出来,允许嵌套控件响应它的正常事件,而不是它的父控件,方法是使用ClickMode枚举,通过添加到相关控件的ClickMode="Pressed"
属性。
希望这能帮上忙,干杯!
https://stackoverflow.com/questions/42065187
复制相似问题