2
我有以下XAML網格:XAML故事板的背景圖像刷
<Grid Style="{StaticResource LayoutRootStyle}" x:Name="mainGrid">
<Grid.Resources>
<Storyboard x:Name="FadeOut">
<DoubleAnimation Duration="3" To="0.0" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="gridBackgroundImageBrush" d:IsOptimized="True"/>
</Storyboard>
<Storyboard x:Name="FadeIn">
<DoubleAnimation Duration="3" To="0.35" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="gridBackgroundImageBrush" d:IsOptimized="True"/>
</Storyboard>
</Grid.Resources>
<Grid.Background>
<ImageBrush x:Name="gridBackgroundImageBrush" ImageSource="{Binding BackgroundImage}" Opacity="0.35">
</ImageBrush>
</Grid.Background>
我想以編程方式啓動的「淡出」的動畫,改變從圖像刷的圖像,然後啓動「淡入」的動畫,就像這樣:
private void t_Tick(object sender, object e)
{
try
{
FadeOut.Begin();
this.DefaultViewModel["BackgroundImage"] = BackgroundImage;
FadeIn.Begin();
}
catch { }
}
但是圖像在沒有任何動畫的情況下改變。我想這個問題是關於如何訪問ImageBrush的「不透明度」屬性。我嘗試了 TargetProperty屬性的語法如下:
(Control.Background).(ImageBrush.Opacity)
爲MSDN所示的是:http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.media.animation.storyboard.settargetproperty.aspx,但它似乎並沒有工作。有人可以幫我解決這個問題嗎?