4
我正在開發Windows 8音樂應用程序。我正在改變當前歌曲/相冊的圖像背景。我想在我改變圖像的同時添加fadeIn/dafeOut動畫,但無法弄清楚我可以如何做到這一點。更改背景圖片時的動畫(C#winrt)
<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設置爲「不透明度」,則動畫可以運行,但適用於整個頁面而不僅僅是背景。