C# 加载故事板的所有效果,直到它';结束

C# 加载故事板的所有效果,直到它';结束,c#,wpf,C#,Wpf,我有一个图像,当用户按下时,不透明度将逐渐消失,直到值为0。但只有当用户按住图像时,效果才会继续。是否有一种可能的方法将代码更改为:当用户按下时,不按住按钮,不透明度淡入效果将保持不变?我希望用XAML来做 <EventTrigger RoutedEvent="Button.Click" SourceName="press"> <EventTrigger.Actions> <BeginStoryboard Storyboard

我有一个图像,当用户按下时,不透明度将逐渐消失,直到值为0。但只有当用户按住图像时,效果才会继续。是否有一种可能的方法将代码更改为:当用户按下时,不按住按钮,不透明度淡入效果将保持不变?我希望用XAML来做

<EventTrigger RoutedEvent="Button.Click" SourceName="press">
        <EventTrigger.Actions>
            <BeginStoryboard Storyboard="{StaticResource showA}"/>
        </EventTrigger.Actions>
    </EventTrigger>

<Button Grid.Column="5" Command="{Binding Path=PressC}" CommandParameter="dot" Style="{StaticResource TransparentButton}">
                <Button.Template>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Grid>
                            <Image Name="image5" Source="/W;component/Images/t.png" Height="100" />
                            <Image Name="pressed5" Source="/W;component/Images/T.png" Height="100" Width="200" Margin="-23,-136,-21,0" Visibility="Hidden" />
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsPressed" Value="True">          
                                <Trigger.EnterActions>
                                    <BeginStoryboard>
                                        <Storyboard>
                                            <DoubleAnimation Storyboard.TargetName="pressed5" Storyboard.TargetProperty="Opacity" Duration="0:0:1.5" From="1" To="0"/>
                                        </Storyboard>
                                    </BeginStoryboard>
                                </Trigger.EnterActions>

                                <Setter Property="Panel.ZIndex" Value="999"/>                           
                                <Setter TargetName="pressed5" Property="Visibility" Value="Visible"/>                                    
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Button.Template>
            </Button>

能否显示完整的xaml?因为图像并没有IsPressed属性,也不清楚它是如何为您工作的。 按钮的类似代码按预期工作:

<Button Background="Aquamarine">
<Button.Style>
  <Style TargetType="Button">
    <Style.Triggers>
      <Trigger Property="IsPressed" Value="True">
        <Trigger.EnterActions>
          <BeginStoryboard>
            <Storyboard>
              <DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="0:0:1.5" From="1" To="0"/>
            </Storyboard>
          </BeginStoryboard>
        </Trigger.EnterActions>
      </Trigger>
    </Style.Triggers>
  </Style>
</Button.Style>    

对于图像,它也适用于EventTrigger:

<Image Source="d:\123.png">
<Image.Style>
  <Style TargetType="Image">
    <Style.Triggers>
      <EventTrigger RoutedEvent="MouseDown">            
          <BeginStoryboard>
            <Storyboard>
              <DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="0:0:1.5" From="1" To="0"/>
            </Storyboard>
          </BeginStoryboard>            
      </EventTrigger>
    </Style.Triggers>
  </Style>
</Image.Style>


好的,现在我看到问题了。只有按下按钮时,您的pressed5图像才可见(
仅在按下按钮时工作。isPressed=True)。所以,当用户停止按下按钮时,图像将不可见,并且看不到动画的结果。我会尝试通过trigget设置不透明度而不是可见性,但我不确定您想要实现哪种效果。Omg如果将
设置为
Value=“False”
,它会起作用!Thx人。实际上我的图像是这样工作的:有两个图像,第二个图像是隐藏的。当我单击第一个图像时,第二个图像将出现,并将在几秒钟内淡出。