WPF:为自定义依赖属性设置动画?

发布于 2024-07-25 05:22:05 字数 555 浏览 1 评论 0原文

假设我已经定义了这样的依赖项:

     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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

春风十里 2024-08-01 05:22:05

您是否尝试在不继承自 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文