Wpf 触发器属性将情节提要重新启动到第一个状态

Wpf 触发器属性将情节提要重新启动到第一个状态,wpf,xaml,triggers,storyboard,wpf-animation,Wpf,Xaml,Triggers,Storyboard,Wpf Animation,我有两个触发事件,分别是和,它们是被压缩的,还有IsMouseOver 当我点击一个按钮时,它将播放故事板: <Trigger Property="IsPressed" Value="True"> <Trigger.EnterActions> <BeginStoryboard Storyboard="{StaticResource MouseDownTimeLine}"/> </Trigger.EnterActions>

我有两个触发事件,分别是
,它们是
被压缩的
,还有
IsMouseOver

当我点击一个按钮时,它将播放故事板:

<Trigger Property="IsPressed" Value="True">
   <Trigger.EnterActions>
       <BeginStoryboard Storyboard="{StaticResource MouseDownTimeLine}"/>
   </Trigger.EnterActions>
   <Trigger.ExitActions>
        <BeginStoryboard Storyboard="{StaticResource MouseUpTimeLine}"/>
   </Trigger.ExitActions>
 </Trigger>
<Storyboard x:Key="MouseDownTimeLine" >
    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Pressed" Storyboard.TargetProperty="Opacity" >
        <SplineDoubleKeyFrame KeyTime="00:00:00.25" Value="1" />
     </DoubleAnimationUsingKeyFrames>
</Storyboard>

<Storyboard x:Key="MouseUpTimeLine">
    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Pressed" Storyboard.TargetProperty="Opacity" >
        <SplineDoubleKeyFrame KeyTime="00:00:00.25" Value="1"/>
     </DoubleAnimationUsingKeyFrames>
</Storyboard>

这是链接到这个故事板的:

<Trigger Property="IsPressed" Value="True">
   <Trigger.EnterActions>
       <BeginStoryboard Storyboard="{StaticResource MouseDownTimeLine}"/>
   </Trigger.EnterActions>
   <Trigger.ExitActions>
        <BeginStoryboard Storyboard="{StaticResource MouseUpTimeLine}"/>
   </Trigger.ExitActions>
 </Trigger>
<Storyboard x:Key="MouseDownTimeLine" >
    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Pressed" Storyboard.TargetProperty="Opacity" >
        <SplineDoubleKeyFrame KeyTime="00:00:00.25" Value="1" />
     </DoubleAnimationUsingKeyFrames>
</Storyboard>

<Storyboard x:Key="MouseUpTimeLine">
    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Pressed" Storyboard.TargetProperty="Opacity" >
        <SplineDoubleKeyFrame KeyTime="00:00:00.25" Value="1"/>
     </DoubleAnimationUsingKeyFrames>
</Storyboard>

另一个按钮也链接到同一情节提要。当第二个按钮被点击时,我希望它像它一样播放故事板,但是第一个按钮返回到正常状态。这是故事板的这一部分

<Storyboard x:Key="MouseExitTimeLine">
     <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Normal" Storyboard.TargetProperty="Opacity" >
          <SplineDoubleKeyFrame KeyTime="00:00:00.00" Value="1"/>
     </DoubleAnimationUsingKeyFrames>

      <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Hover" Storyboard.TargetProperty="Opacity" >
           <SplineDoubleKeyFrame KeyTime="00:00:00.00" Value="0"/>
       </DoubleAnimationUsingKeyFrames>
</Storyboard>


当单击第二个按钮时,如何触发第一个按钮重置为正常状态

这里可能我错了,但似乎您在按钮模板中烘焙了单选按钮功能。当您单击一个按钮时,它保持“单击”(或选中),当您单击另一个按钮时,它从第一个按钮“释放”单击

我会将模板的目标类型更改为
RadioButton
,并将触发器更改为:

<Trigger Property="IsChecked" Value="True">
   <Trigger.EnterActions>
       <BeginStoryboard x:Name="ButtonCheckedStoryboardBegin"
                        Storyboard="{StaticResource MouseDownTimeLine}"/>
   </Trigger.EnterActions>
   <Trigger.ExitActions>
       <StopStoryboard BeginStoryboardName="ButtonCheckedStoryboardBegin"/>
   </Trigger.ExitActions>
</Trigger>
[第二个选项可以按原样使用-持续时间为零,但不太优雅,IMO]

此外,MouseExitTimeLine中“Hover”的动画是多余的,可以删除,因为MouseDownTimeLine没有在“Hover”上设置任何内容


现在,在布局中的每个
RadioButton
实例上,添加
GroupName=“
”。在任何给定的时间点,只能检查组中的一个单选按钮。

当我将模板更改为RadioButton时,会出现大量错误<代码>RadioButton控件模板TargetType与模板类型按钮不匹配?您需要将
按钮的实例更改为
RadioButton