【发布时间】:2013-11-02 21:40:20
【问题描述】:
有没有办法在 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>
我想每 10 秒淡出背景图像 --> 更改图像 --> 再次淡入。
我已经尝试过使用以下代码行:
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();
但这不起作用。如果情节提要完成,图像将发生变化,但没有褪色效果。
HubSection.Background 不是“动画”吗?
【问题讨论】:
标签: c# windows-runtime storyboard winrt-xaml windows-8.1