WPF:为自定义依赖属性设置动画?
假设我已经定义了这样的依赖项:
public class MySampleClass
{public static DependencyProperty MyDoubleProperty = DependencyProperty.Register("MyDouble", typeof(double), typeof(MySampleClass));
public double MyDouble
{
get
{
return (double)GetValue(MyDoubleProperty);
}
set
{
SetValue(MyDoubleProperty, value);
}
}
}
我想将 DoubleAnimation 应用于该值。 我怎样才能做到这一点? 以前,我一直通过调用 UIElement 的 BeginAnimation 方法来使用 DoubleAnimations。
感谢您的帮助!
Let's say that I've defined a dependency like this:
public class MySampleClass
{public static DependencyProperty MyDoubleProperty = DependencyProperty.Register("MyDouble", typeof(double), typeof(MySampleClass));
public double MyDouble
{
get
{
return (double)GetValue(MyDoubleProperty);
}
set
{
SetValue(MyDoubleProperty, value);
}
}
}
I'd like to apply a DoubleAnimation to this value. How can I do this? Always before, I've used DoubleAnimations by calling the BeginAnimation method of a UIElement.
Thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试在不继承自 UIElement 的类上使用 DoubleAnimation? 如果没有,您至少应该继承 Animatable 或其他也支持 BeginAnimation 的基类。
Are you trying to use a DoubleAnimation on a class that doesn't inherit from UIElement? If not, you should at least inherit from Animatable, or some other base class which also supports BeginAnimation.