Reputation: 1182
I have a ComboBox
that includes a CheckBox
by changing the DataTemplate
, this works fine when done on its own, but when moving it into a DataGrid
the CheckBox
is not clickable.
Working Code:
<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>
Proof:
But when adding this same logic to a DataGrid
, instead of adding the checkmark to the CheckBox
, the ComboBox
closes with nothing selected.
Non working code:
<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>
Upvotes: 1
Views: 514
Reputation: 23290
When you have a nested control whose parent would normally hijack HitTestVisibility you can bubble out and allow the nested control to respond to it's normal events in lieu of it's parent by using ClickMode enumeration via the property of ClickMode="Pressed"
being added to the control in question.
Hope this helps, cheers!
Upvotes: 1