用于背景ImageBrush的XAML序列图像板

用于背景ImageBrush的XAML序列图像板,xaml,windows-8,windows-store-apps,Xaml,Windows 8,Windows Store Apps,我有以下XAML网格: <Grid Style="{StaticResource LayoutRootStyle}" x:Name="mainGrid"> <Grid.Resources> <Storyboard x:Name="FadeOut"> <DoubleAnimation Duration="3" To="0.0" Storyboard.TargetProperty="Opacity" Stor

我有以下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>
但是,图像正在更改,没有任何动画。我想问题在于如何访问ImageBrush的“不透明度”属性。我尝试了下面的语法 TargetProperty属性:

(Control.Background).(ImageBrush.Opacity)

正如msdn在这里所示:但它似乎不起作用。有人能帮我解决这个问题吗?

解决方案是创建一个图像控件,而不是使用ImageBrush绘制图像,然后定义淡入淡出的视觉状态:

<Grid Style="{StaticResource LayoutRootStyle}" x:Name="mainGrid">
    <Image Grid.RowSpan="2" x:Name="gridBackgroundImageBrush" Source="{Binding BackgroundImage}" />
</Grid>
<VisualStateGroup x:Name="FadeStates">
        <VisualState x:Name="FadeOutState">
             <Storyboard>
                  <DoubleAnimation Duration="{Binding fadeDuration}" From="0.5" To="0.0" x:Name="fadeOutAnimation" 
                                     Storyboard.TargetProperty="Opacity" 
                                     Storyboard.TargetName="gridBackgroundImageBrush"  />
             </Storyboard>
        </VisualState>
        <VisualState x:Name="FadeInState">
             <Storyboard>
                  <DoubleAnimation Duration="{Binding fadeDuration}" From="0.0" To="0.5" x:Name="fadeInAnimation" 
                                     Storyboard.TargetProperty="Opacity"
                                     Storyboard.TargetName="gridBackgroundImageBrush" />
            </Storyboard>
        </VisualState>
 </VisualStateGroup>

<Grid Style="{StaticResource LayoutRootStyle}" x:Name="mainGrid">
    <Image Grid.RowSpan="2" x:Name="gridBackgroundImageBrush" Source="{Binding BackgroundImage}" />
</Grid>
<VisualStateGroup x:Name="FadeStates">
        <VisualState x:Name="FadeOutState">
             <Storyboard>
                  <DoubleAnimation Duration="{Binding fadeDuration}" From="0.5" To="0.0" x:Name="fadeOutAnimation" 
                                     Storyboard.TargetProperty="Opacity" 
                                     Storyboard.TargetName="gridBackgroundImageBrush"  />
             </Storyboard>
        </VisualState>
        <VisualState x:Name="FadeInState">
             <Storyboard>
                  <DoubleAnimation Duration="{Binding fadeDuration}" From="0.0" To="0.5" x:Name="fadeInAnimation" 
                                     Storyboard.TargetProperty="Opacity"
                                     Storyboard.TargetName="gridBackgroundImageBrush" />
            </Storyboard>
        </VisualState>
 </VisualStateGroup>