silverlight - 在模型列表上手动调用 PropertyChanged

标签 silverlight mvvm

在我的 ViewModel 中,我有一个属性,它是模型列表:

private List<LocationModel> _locations = null;
public List<LocationModel> Locations
{
    get
    {
        return this._locations;
    }
    set
    {
        this._locations = value;
        RaisePropertyChanged("Locations");
    }
}

但是 LocationModel类没有实现 INotifyPropertyChanged ,所以当我更新列表中某个项目的属性时,UI 不会更新。我试图通过在更改列表项后手动引发事件来实现这一点,但这不起作用。有人可以解释为什么这种方法不起作用吗?

提前致谢。

最佳答案

INotifyPropertyChanged仅适用于实现该接口(interface)的对象的实例属性。不是实现接口(interface)的属性的属性。 LocationModel需要执行INotifyPropertyChanged如果你想让这个工作。如果您没有 LocationModel 的源代码,或者由于任何原因无法更改它,则需要将所有要对其使用react的属性包装在实现 INotifyPropertyChanged 的包装类中。 .您可以使用 DynamicProxy 动态换行(死链接)DynamicProxy (cached) .

关于silverlight - 在模型列表上手动调用 PropertyChanged,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11248894/

相关文章:

xaml - 我应该如何在 Windows 应用商店应用程序中显示带有绑定(bind)数据的格式化文本?

c# - 绑定(bind)到 DataTable 时更改 DataGrid 上的空值外观

ios - 在 MVVM 模式中使用闭包将 View 模型与 View Controller 绑定(bind)是一种好的做法吗?

c# - 如何在 Windows Phone 键盘上获得提交按钮?

c# - 为什么 Silverlight TextBox 使用\r 而不是 Environment.Newline (\r\n) 作为换行符?

c# - Silverlight 套接字中的超时

c# - MVVM 和更新属性

Silverlight Prism 区域事件

c# - 是 Silverlight .Net 吗? (删除前阅读)

c# - Model/ViewModel 设计中的类继承错误