HubSection背景的双动画(Windows 8.1、XAML、C#)

HubSection背景的双动画(Windows 8.1、XAML、C#),c#,windows-runtime,storyboard,winrt-xaml,windows-8.1,C#,Windows Runtime,Storyboard,Winrt Xaml,Windows 8.1,在Windows 8.1 XAML/C#控件中,是否有方法淡出和淡入HubSection的背景图像 实际上我有这个XAML代码: <HubSection x:Name="Section0" Width="700" Margin="0,0,80,0" VerticalContentAlignment="Bottom"> <HubSection.Background> <ImageBrush x:Name="Section0Background" Im

在Windows 8.1 XAML/C#控件中,是否有方法淡出和淡入
HubSection
的背景图像

实际上我有这个XAML代码:

<HubSection x:Name="Section0" Width="700" Margin="0,0,80,0" VerticalContentAlignment="Bottom">
   <HubSection.Background>
      <ImageBrush x:Name="Section0Background" ImageSource="/Assets/images/img1.jpg" Stretch="UniformToFill" />
   </HubSection.Background>
   <!--... some other markup ... -->
</HubSection>
但这是行不通的。如果故事板已完成,图像将更改,但不会出现褪色效果。
HubSection.Background
不是“可动画的”

我不相信一旦控件位于HubSection中,您就可以引用代码中的控件。因此,您的Storyboard.SetTarget可能是它试图引用Section0Background的罪魁祸首。您可能可以在XAML中构建大部分动画,但对于图像的更改,您需要做的是绑定ImageBrush的ImageSource属性并设置HubSection的DataContext

然后,在脚本完成事件激发时的代码隐藏中,更改ViewModel(设置为HubSection的DataContext),这将引发一个事件,该事件将重新绑定ImageSource属性

总之,您不能在HubbSection中引用控件。只能通过数据绑定更改属性

这是一个类似的例子

Storyboard storyboard = new Storyboard();

DoubleAnimation animation = new DoubleAnimation();
animation.From = 1.0;
animation.To = 0.0;
animation.BeginTime = TimeSpan.FromSeconds(0);
animation.Duration = new Duration(TimeSpan.FromMilliseconds(200));

storyboard.Children.Add(animation);

Storyboard.SetTargetProperty(animation, "Opacity");
Storyboard.SetTarget(animation, Section0Background);

storyboard.Completed += storyboard_Completed; // --> on complete change image and fade in
storyboard.Begin();