0

我有一个图像,当用户按下时,不透明度会逐渐消失,直到值为 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>
4

1 回答 1

1

你能展示你的完整xaml吗?因为 Image 没有 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>    

对于 Image 它也适用于 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>

于 2012-04-10T07:21:09.397 回答