使用FadeInThemeAnimation作为WinRT中的过渡

Vil*_*ger 7 c# xaml microsoft-metro windows-runtime winrt-xaml

我在C#/ XAML WinRT应用程序中使用托管在服务器上的图像.当下载该图像时,我希望它能够淡入.我注意到了FadeInThemeAnimation我希望使用的内容.但是,我想像它一样使用它EntranceThemeTransition.有没有办法做到这一点?如果是这样,怎么样?

小智 10

我遇到了同样的问题,但找到了一个解决方案,我认为分享它可能仍然有用.

显然,这FadeInThemeAnimation是一种特殊的动画,不像你想象的那样对Opacity和Visibility起作用,但对于一个项目的RenderTransform.我只是设法在首先淡出项目时使其工作FadeOutThemeAnimation.

但这是一个解决方法.在您的XAML中,将Storyboard添加到图像容器的Resources中,如下所示:

<Grid>
    <Grid.Resources>
        <Storyboard x:Name="ImageFadeInStoryboard">
            <DoubleAnimation From="0" To="1" Storyboard.TargetName="yourImage" Storyboard.TargetProperty="Opacity" Duration="0:0:0.6" />
        </Storyboard>
    </Grid.Resources>
    <Image x:Name="yourImage" Source="{Binding ...}"/>
...
Run Code Online (Sandbox Code Playgroud)

然后为图像的ImageOpened事件添加一个处理程序:

<Image x:Name="yourImage" Source="{Binding ...}" ImageOpened="OnImageOpened"/>
Run Code Online (Sandbox Code Playgroud)

在代码隐藏中:

private void OnImageOpened(object sender, RoutedEventArgs e)
{
    ImageFadeInStoryboard.Begin();
}
Run Code Online (Sandbox Code Playgroud)

希望有帮助:)