1

当我将鼠标放在第一张图像上时,会出现第二张图像。当我将鼠标放在第一张图像上时,第二张图像会立即消失。即使在第一张图像上离开鼠标后,如何使第二张图像继续显示几秒钟?

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

<Button Grid.Column="1" Command="{Binding Path=PressC}" CommandParameter="cam" Style="{StaticResource TransparentButton}">
            <Button.Template>
                <ControlTemplate TargetType="{x:Type Button}">
                    <Grid>
                        <Image Name="1" Source="/W;component/Images/1.png" Height="100" />
                        <Image Name="2" Source="/W;component/Images/2.png" Height="200" Width="100" Margin="50,-33,-50,0" Visibility="Hidden" />
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">          
                            <Trigger.EnterActions>
                                    <BeginStoryboard>
                                        <Storyboard>
                                            <DoubleAnimation Storyboard.TargetName="imgPressedKeyboard05" Storyboard.TargetProperty="Opacity" From="0" To="2" Duration="0:0:.5" BeginTime="0:0:0"/>
                                            <DoubleAnimation Storyboard.TargetName="imgPressedKeyboard05" Storyboard.TargetProperty="Opacity" From="2" To="0" Duration="0:0:.5" BeginTime="0:0:1"/>
                                        </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

使用动画而不是简单的Setter. 一个EnterActions使其可见,一个在ExitActions给定时间后将其隐藏。要制作动画Visibility,您可以使用ObjectAnimationUsingKeyFrames.

于 2012-04-12T23:40:38.720 回答