1

我可以使用以下代码淡入/淡出

<Storyboard x:Name="EnterStoryboard">
     <FadeOutThemeAnimation Storyboard.TargetName="PauseImage" />
</Storyboard>
<Storyboard x:Name="ExitStoryboard">
     <FadeInThemeAnimation Storyboard.TargetName="PauseImage" />
</Storyboard>

淡入淡出:

EnterStoryboard.Begin();

淡出:

ExitStoryboard.Begin();

如果元素从一开始就隐藏(我尝试设置opacity=0and visibility=collapsed) ,我该如何淡入淡出。

编辑:
基于 AstiK 解决方案,这里是新Storyboard的 s (而不是内置FadeInThemeAnimation/ FadeOutThemeAnimation

<Storyboard x:Name="EnterStoryboard">
    <DoubleAnimation BeginTime="00:00:00" Storyboard.TargetProperty="(UIElement.Opacity)" From="0" To="1" Duration="00:00:00.3"  Storyboard.TargetName="Image"/>
</Storyboard>
<Storyboard x:Name="ExitStoryboard">
    <DoubleAnimation BeginTime="00:00:00" Storyboard.TargetProperty="(UIElement.Opacity)" From="1" To="0" Duration="00:00:00.3"  Storyboard.TargetName="Image"/>
</Storyboard>
4

2 回答 2

1

在您原来的方法中,您应该从一开始就保留Opacity ="0"Visibility="Visible"。我想你正在寻找这样的东西:

<Grid Height="50" Width="100" Background="Red" Opacity="0">
        <Grid.Style>
            <Style TargetType="Grid">
                <Style.Triggers>
                    <EventTrigger RoutedEvent="MouseEnter">
                        <BeginStoryboard>
                            <Storyboard>
                                <Storyboard  >
                                    <DoubleAnimation BeginTime="00:00:00"  Storyboard.TargetProperty="(UIElement.Opacity)" From="0" To="1" Duration="00:00:03"/>
                                </Storyboard>
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger>
                </Style.Triggers>
            </Style>
        </Grid.Style>
    </Grid>
于 2013-08-30T12:28:28.210 回答
0

用这个:

<Storyboard  x:Name="EnterStoryboard">
       <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="PauseImage">
            <DiscreteObjectKeyFrame KeyTime="0">
                <DiscreteObjectKeyFrame.Value>
                    <Visibility>Visible</Visibility>
                </DiscreteObjectKeyFrame.Value>
            </DiscreteObjectKeyFrame>
        </ObjectAnimationUsingKeyFrames>
        <FadeOutThemeAnimation Storyboard.TargetName="PauseImage" />

设置为以相同的方式折叠ExitStoryboard

于 2013-08-30T10:53:11.667 回答