火灾事件的价值变化是双重的 [英] Fire event on value change of double

查看:167
本文介绍了火灾事件的价值变化是双重的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在自定义类中使用了 INotifyPropertyChanged ,以便在变量发生变化时触发事件,但我想知道是否有一种简单的方式来触发事件单个变量的变化,例如一个double。

I've used INotifyPropertyChanged within a custom class to fire an event when a variable has changed, but I was wondering if there was a simple way to fire an event on a single variable's change, such as a double.

例如,在WPF应用程序中,如果我有

For instance, in a WPF app, if I have

private double a;

MainWindow.xaml.cs 有一个简单的方式可以在任何时间点击事件 a 分配给?

in MainWindow.xaml.cs, is there a simple way to fire the event any time a is assigned to?

推荐答案

如果我正确理解你,你需要为a创建一个Setter,然后触发validychange事件/自定义事件,而不是封装 a

If I understand you correctly, you need to create a Setter for a, which then fires the properychange event/custom event instead of encapsulate a into a class.

如下所示:

private double a;

    public double A
    {
        get { return a; }
        set { a = value;
              firepropertyChange(a);
            }
    }

这篇关于火灾事件的价值变化是双重的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆