我有以下 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>
我想以编程方式启动“FadeOut”动画并从 ImageBrush 更改图像,然后启动“FadeIn”动画,如下所示:
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但它似乎不起作用。有人可以帮我解决这个问题吗?