我为包装面板上的按钮编写此代码。 我想用不透明动画显示它们,但是当编译器到达s.begin();时,它不起作用,并向我显示错误。 请指导我修复此代码。 我在互联网上其他代码的帮助下编写了它们。 一件事是因为我不知道如何延迟动画,所以我写那些ifs。
BindingContext
错误是: System.InvalidOperationException:'未为'System.Windows.Media.Animation.DoubleAnimation'指定目标。'
答案 0 :(得分:1)
private void AccountBtn_Loaded(object sender, RoutedEventArgs e)
{
DoubleAnimation Opacityanimation = new DoubleAnimation
{
From = 0,
To = 100,
Duration = TimeSpan.FromSeconds(90)
};
Storyboard sb = new Storyboard();
Storyboard.SetTargetProperty(Opacityanimation, new PropertyPath(Ellipse.OpacityProperty));
Storyboard.SetTarget(Opacityanimation, AccountBtn);
Storyboard s = new Storyboard();
s.Children.Add(Opacityanimation);
s.Begin();
}
答案 1 :(得分:0)
我为自己的问题找到了解决方案,那就是我们可以在每个控件的加载事件上使用这些代码,例如我在此处编写的代码,并且可以通过写ifs来延迟执行。
private void AccountBtn_Loaded(object sender, RoutedEventArgs e)
{
DoubleAnimation Opacityanimation = new DoubleAnimation
{
From = 0,
To = 100,
Duration = TimeSpan.FromSeconds(90)
};
Storyboard sb = new Storyboard();
Storyboard.SetTargetProperty(Opacityanimation, new PropertyPath(Ellipse.OpacityProperty));
Storyboard.SetTarget(Opacityanimation, AccountBtn);
Storyboard s = new Storyboard();
s.Children.Add(Opacityanimation);
s.Begin();
}