Xaml 在UWP中设置渐变笔刷动画
我想为控件的fill属性使用的GradientBrush(在我的例子中是LinearGradientBrush)设置动画。我试图改变我的故事板中的渐变停止值(偏移或颜色),但它似乎不起作用。我以网格的背景作为示例的目标:Xaml 在UWP中设置渐变笔刷动画,xaml,animation,uwp,gradient,Xaml,Animation,Uwp,Gradient,我想为控件的fill属性使用的GradientBrush(在我的例子中是LinearGradientBrush)设置动画。我试图改变我的故事板中的渐变停止值(偏移或颜色),但它似乎不起作用。我以网格的背景作为示例的目标: <Grid x:Name="LogoGrid" Height="512" Width="512"> <Grid.Background> <LinearGradientBrush x:Name="LogoBackgroundB
<Grid x:Name="LogoGrid" Height="512" Width="512">
<Grid.Background>
<LinearGradientBrush x:Name="LogoBackgroundBrush" StartPoint="0 0" EndPoint="1 1">
<GradientStop x:Name="Stop0" Color="Transparent" Offset="0" />
<GradientStop x:Name="Stop1" Color="#80FFFFFF" Offset="0.5" />
<GradientStop x:Name="Stop2" Color="Transparent" Offset="1" />
</LinearGradientBrush>
</Grid.Background>
</Grid>
故事板:
<Storyboard x:Key="LoadingStoryBoard">
<ColorAnimationUsingKeyFrames Storyboard.TargetName="LogoGrid"
Storyboard.TargetProperty="(UIElement.Background).(LinearGradientBrush.GradientStops)[1].(GradientStop.Color)"
RepeatBehavior="Forever" EnableDependentAnimation="True">
<LinearColorKeyFrame Value="#40000000" KeyTime="0:0:1" />
<LinearColorKeyFrame Value="#A0FFFFFF" KeyTime="0:0:2" />
</ColorAnimationUsingKeyFrames>
</Storyboard>
您是否确保将
启用Dependentanimation
设置为true
您可以查看另一个类似的问题以获得完整的示例。您没有提到如何启动故事板。无论如何,我通过将
x:Key
替换为x:Name
(否则,我无法从代码中引用情节提要)使其正常工作
XAML
编辑
Tangetial:显示如何通过x:Key
而不是我的x:Name
访问情节提要。诀窍是通过资源访问故事板,例如:
((Storyboard)Resources["LoadingStoryboard"]).Begin();
是的,此属性已启用,我尝试设置偏移(DoubleAnimation)或颜色(ColorAnimation)的动画。我更新了我的问题以了解更多细节。我尝试了这个解决方案,但根本没有彩色动画。我的故事板启动良好(我尝试过其他动画),不知道问题出在哪里。属性“EnableDependentAnimation”设置为true。@BertrandC:我在GitHub上安装了一个最小的、自包含的项目(请参阅更新的答案)。如果这对你不起作用,我不知道问题出在哪里。谢谢你的帮助,我会检查这个。
public sealed partial class MainPage
{
public MainPage()
{
InitializeComponent();
Loaded += (sender, args) => LoadingStoryBoard.Begin();
}
}
((Storyboard)Resources["LoadingStoryboard"]).Begin();