简体   繁体   English

如何在MVVM中的另一个类中处理One类中属性的属性更改事件

[英]How to handle property changed event of a property in One class from another class in MVVM

Say I have description property in one class: 假设我在一个类中有描述属性:

public string Description
{
    get
    {
        return _description;
    }

    set
    {
        _description = value;
        RaisePropertyChanged("Description");
    }
}

I would like to monitor the change in these value in some other type. 我想监视其他类型的这些值的变化。 How do I wire up? 我如何连线?

You can subscribe the event PropertyChanged. 您可以订阅PropertyChanged事件。

myModel.PropertyChanged+=(s,e)=>{ /* your handler here */};

as the @stijn comment point, unsubscribing can be required if the model became unused to avoid memory leaks. 作为@stijn注释点,如果模型未使用以避免内存泄漏,则可能需要取消订阅。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM