组合框DataTemplate中的WPF复选框在DataGrid中不起作用
我有一个组合框DataTemplate中的WPF复选框在DataGrid中不起作用,wpf,xaml,datagrid,datatemplate,Wpf,Xaml,Datagrid,Datatemplate,我有一个组合框,其中包含一个复选框,通过更改数据模板,这在单独操作时可以正常工作,但当将其移动到数据网格中时,复选框不可单击 工作代码: <ComboBox ItemsSource="{Binding WrapUpHelper.WrapUps}"> <ComboBox.ItemTemplate> <DataTemplate> <Stac
组合框
,其中包含一个复选框
,通过更改数据模板
,这在单独操作时可以正常工作,但当将其移动到数据网格
中时,复选框
不可单击
工作代码:
<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>
当您有一个嵌套控件,其父控件通常会劫持HitTestVisibility时,您可以冒泡出来,允许嵌套控件通过添加到相关控件中的
ClickMode=“Pressed”
属性使用枚举来响应它的正常事件,而不是它的父控件
希望这有帮助,干杯 你对他们有什么看法吗?可以尝试将
ClickMode=“Press”
添加到CB's@ChrisW. 请将此更改为回答,我可以将其标记为正确,这允许在数据网格中勾选复选框
,现在唯一的问题是每次单击组合框
都会关闭。好的,PS对于第二部分,我总是这样做。:)@克里斯。谢谢,在要求我在组合框
中添加更多功能后,我选择了另一种解决方案,因为数据网格
中的空间有点狭窄。但对于任何有同样问题的人来说,这似乎是一个简单的解决方案。
<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>