【发布时间】:2018-12-11 15:38:53
【问题描述】:
我在 Combobox 中有复选框,我想点击它们:
如果我单击复选框或复选框的“内容”,它将选中该复选框,但如果我单击“内容”旁边的空白区域,它将仅选中组合框中的此复选框。
如何防止这种情况发生?如果我单击整个字段,而不仅仅是文本,我想选中该框。
这是我的代码:
<ComboBox Margin="2,2,2,0" ItemsSource="{Binding DataContext.AllTags, ElementName=self}" >
<ComboBox.ItemTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding IsChecked}" Content="{Binding Name}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Checked">
<i:InvokeCommandAction Command="{Binding DataContext.CmdCmx_UpdateTags, ElementName=self}" CommandParameter="{Binding}" />
</i:EventTrigger>
<i:EventTrigger EventName="Unchecked">
<i:InvokeCommandAction Command="{Binding DataContext.CmdCmx_UpdateTags, ElementName=self}" CommandParameter="{Binding}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</CheckBox>
</DataTemplate>
</ComboBox.ItemTemplate>
<i:Interaction.Triggers>
<i:EventTrigger EventName="DropDownOpened">
<i:InvokeCommandAction Command="{Binding DataContext.CmdCmx_ClearTags, ElementName=self}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
【问题讨论】:
-
如果您不需要
ComboBox的选择功能,请参阅我的答案here 作为替代