checkBox有这样的模板
<ControlTemplate x:Key="CustomCheckBox" TargetType="CheckBox">
<StackPanel Orientation="Horizontal" Margin="11, 0, 0, 0">
<Canvas VerticalAlignment="Center" Width="30" Height="19" Margin="{TemplateBinding Padding}">
<Ellipse x:Name="CheckBoxBackCircle" Width="50" Height="50" Fill="#F8F8FA" Opacity="0">
<Ellipse.RenderTransform>
<TranslateTransform X="-15" Y="-15"/>
</Ellipse.RenderTransform>
</Ellipse>
<Path x:Name="CheckBoxSquare" Data="M.5,12.5 l0,4 q0,2 2,2 l15,0 q1,0 1,-2 l0,-14 q0,-2 -2,-2 l-15,0 q-1,0 -1,2 l0,10" Stroke="#D6D9DF" StrokeThickness="1.4" StrokeDashArray="69.5" Fill="White" Stretch="Fill" Width="20" Height="20"/>
<Path x:Name="CheckBoxCheck" Data="M.5,12.5 l7,6 l11,-15" Stroke="#D6D9DF" StrokeThickness="1.4" StrokeDashArray="28" StrokeDashOffset="28" />
</Canvas>
<ContentControl VerticalAlignment="Center" Content="{TemplateBinding Content}"></ContentControl>
</StackPanel>
<ControlTemplate.Triggers>
<EventTrigger RoutedEvent="MouseEnter">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard TargetName="CheckBoxBackCircle" TargetProperty="Opacity">
<DoubleAnimation To="1" Duration="0:0:0:0.2" FillBehavior="HoldEnd"></DoubleAnimation>
</Storyboard>
</BeginStoryboard>
<BeginStoryboard>
<Storyboard TargetName="CheckBoxSquare" TargetProperty="Stroke.Color">
<ColorAnimation To="#6FA2F6" Duration="0:0:0:0.2" FillBehavior="HoldEnd"></ColorAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
<EventTrigger RoutedEvent="MouseLeave">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard TargetName="CheckBoxBackCircle" TargetProperty="Opacity">
<DoubleAnimation To="0" Duration="0:0:0:0.2" FillBehavior="HoldEnd"></DoubleAnimation>
</Storyboard>
</BeginStoryboard>
<BeginStoryboard>
<Storyboard TargetName="CheckBoxSquare" TargetProperty="Stroke.Color">
<ColorAnimation To="#D6D9DF" Duration="0:0:0:0.2" FillBehavior="HoldEnd"></ColorAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
<EventTrigger RoutedEvent="Checked">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard TargetName="CheckBoxSquare" TargetProperty="StrokeDashOffset">
<DoubleAnimation To="-69.5" Duration="0:0:0:1" FillBehavior="HoldEnd"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
问题是这个触发器。
<EventTrigger RoutedEvent="Checked">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard TargetName="CheckBoxSquare" TargetProperty="StrokeDashOffset">
<DoubleAnimation To="-69.5" Duration="0:0:0:1" FillBehavior="HoldEnd"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
这是带有此模板的复选框
<CheckBox Template="{StaticResource CustomCheckBox}" FontSize="17" HorizontalAlignment="Center"></CheckBox>
错误:
如果为属性设置不同的值RoutedEvent
,例如 MouseMove,那么一切都会正常工作(但似乎这不适用于所有事件,因为Click
和Unchecked
会弹出相同的错误)。
请帮帮我!
您需要注册 CheckBox.Click 它应该可以工作。检查。你也可以 CheckBox.Checked