WPF CheckBox UnCheck 事件未触发
WPF CheckBox UnCheck Event Not Firing
我在 ItemsControl 中有一个复选框。它有一个用于 Checked
和 UnChecked
事件的 EventTrigger。它还绑定到具有多个 CommandParameters
的 Command
。 Checked
事件触发得很好。
但是,UnChecked
事件不会触发。我错过了什么?
<ItemsControl Grid.Column ="2"
Grid.Row ="0"
ItemsSource ="{Binding ParameterOptionGroup.ParameterOptions}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding State, Converter={StaticResource BoolToEntityState}, Mode=OneWay}">
<trigger:Interaction.Triggers>
<trigger:EventTrigger EventName="Checked">
<trigger:InvokeCommandAction Command ="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}},
Path=DataContext.InitiateParameterAnswer}">
<trigger:InvokeCommandAction.CommandParameter>
<MultiBinding Converter="{StaticResource GuidAndParameterOptionToTuple}">
<Binding Path="DataContext" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type CheckBox}}"></Binding>
<Binding Path="DataContext.Id" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}"></Binding>
<Binding Path="Text" ElementName="txtRemarks" />
<Binding Source="True" />
<Binding Source="10" />
</MultiBinding>
</trigger:InvokeCommandAction.CommandParameter>
</trigger:InvokeCommandAction>
</trigger:EventTrigger>
</trigger:Interaction.Triggers>
<trigger:EventTrigger EventName="UnChecked">
<trigger:InvokeCommandAction Command ="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}},
Path=DataContext.InitiateParameterAnswer}">
<trigger:InvokeCommandAction.CommandParameter>
<MultiBinding Converter="{StaticResource GuidAndParameterOptionToTuple}">
<Binding Path="DataContext" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type CheckBox}}"></Binding>
<Binding Path="DataContext.Id" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}"></Binding>
<Binding Path="Text" ElementName="txtRemarks" />
<Binding Source="False" />
<Binding Source="5" />
</MultiBinding>
</trigger:InvokeCommandAction.CommandParameter>
</trigger:InvokeCommandAction>
</trigger:EventTrigger>
</CheckBox>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
正如@Bort 指出的那样,事件名称应该是 Unchecked
而不是 UnChecked
。
我在 ItemsControl 中有一个复选框。它有一个用于 Checked
和 UnChecked
事件的 EventTrigger。它还绑定到具有多个 CommandParameters
的 Command
。 Checked
事件触发得很好。
但是,UnChecked
事件不会触发。我错过了什么?
<ItemsControl Grid.Column ="2"
Grid.Row ="0"
ItemsSource ="{Binding ParameterOptionGroup.ParameterOptions}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding State, Converter={StaticResource BoolToEntityState}, Mode=OneWay}">
<trigger:Interaction.Triggers>
<trigger:EventTrigger EventName="Checked">
<trigger:InvokeCommandAction Command ="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}},
Path=DataContext.InitiateParameterAnswer}">
<trigger:InvokeCommandAction.CommandParameter>
<MultiBinding Converter="{StaticResource GuidAndParameterOptionToTuple}">
<Binding Path="DataContext" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type CheckBox}}"></Binding>
<Binding Path="DataContext.Id" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}"></Binding>
<Binding Path="Text" ElementName="txtRemarks" />
<Binding Source="True" />
<Binding Source="10" />
</MultiBinding>
</trigger:InvokeCommandAction.CommandParameter>
</trigger:InvokeCommandAction>
</trigger:EventTrigger>
</trigger:Interaction.Triggers>
<trigger:EventTrigger EventName="UnChecked">
<trigger:InvokeCommandAction Command ="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}},
Path=DataContext.InitiateParameterAnswer}">
<trigger:InvokeCommandAction.CommandParameter>
<MultiBinding Converter="{StaticResource GuidAndParameterOptionToTuple}">
<Binding Path="DataContext" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type CheckBox}}"></Binding>
<Binding Path="DataContext.Id" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}"></Binding>
<Binding Path="Text" ElementName="txtRemarks" />
<Binding Source="False" />
<Binding Source="5" />
</MultiBinding>
</trigger:InvokeCommandAction.CommandParameter>
</trigger:InvokeCommandAction>
</trigger:EventTrigger>
</CheckBox>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
正如@Bort 指出的那样,事件名称应该是 Unchecked
而不是 UnChecked
。