windows – 更改背景图像时的动画(C#winrt)

我正在使用 Windows 8音乐应用程序.我正在用当前歌曲/专辑的图像改变页面的背景.我想在更改图像时添加fadeIn / dafeOut动画,但无法弄清楚我该怎么做.

<Grid  x:Name="LayoutRoot" Background="{StaticResource  ApplicationPageBackgroundThemeBrush}">
        <Grid.Resources>
            <Storyboard x:Name="fadeOutStoryBoard">
                <DoubleAnimation
                    Storyboard.TargetName="LayoutRoot"
                    Storyboard.TargetProperty="(LayoutRoot.Background).(ImageBrush.Opacity)"
                    From="1.0" To="0.0" Duration="0:0:10"/>
            </Storyboard>
            <Storyboard x:Name="fadeInStoryBoard">
                <DoubleAnimation
                    Storyboard.TargetName="LayoutRoot"
                    Storyboard.TargetProperty="(LayoutRoot.Background).(ImageBrush.Opacity)"
                    From="0" To="1.0" Duration="0:0:10"/>
            </Storyboard>
        </Grid.Resources>
    </Grid>

    In C# code: 
    ImageBrush image = new ImageBrush();
    image.ImageSource = new BitmapImage(imageUri);
    fadeOutStoryBoard.Begin();
    MainPage.Current.LayoutRoot.Background = image;
    fadeInStoryBoard.Begin();

图像变化很好,但我看不到动画.我尝试将TargetProperty更改为(LayoutRoot.Background).Opacity或(LayoutRoot.Background).(SolidColorBrush.Opacity)但没有运气.如果我将TargetProperty设置为“Opacity”,则动画可以工作,但适用于整个页面而不仅仅是背景.

解决方法

不要将图像作为页面的背景,添加另一个将保留背景的网格/边框.在动画中使用不透明度作为TargetProperty.

原因是当前动画正在处理旧图像画笔而不是您创建的新图像画笔.

相关文章

文章浏览阅读2.2k次,点赞6次,收藏20次。在我们平时办公工作...
文章浏览阅读1k次。解决 Windows make command not found 和...
文章浏览阅读3.2k次,点赞2次,收藏6次。2、鼠标依次点击“计...
文章浏览阅读1.3w次。蓝光版属于高清版的一种。BD英文全名是...
文章浏览阅读974次,点赞7次,收藏8次。提供了更强大的功能,...
文章浏览阅读1.4w次,点赞5次,收藏22次。如果使用iterator的...