我在整体MVVM组织方面遇到了一些问题。我有一个由云api提供的AuthenticatedUser。这个AuthenticatedUser用户有像名字,年龄等字段....
我想将这些绑定到控件。我知道我必须创建包含NotifyPropertyChanged的属性才能使其工作。
因此,我创建了一个包含这些属性的模型,并从AuthenticatedUser返回了字段。问题是AuthenticatedUser正在填充这些字段。因此,属性不会以任何方式“设置”,因此也没有绑定通知。
这里有一些代码片段:
public string Name // I want properties like this to bind to a textblock. The User object(provided by the cloud service) has these as fields. The Problem is that these are also changing so i have to update the binding!
{
get { return User.Name; }
}
答案 0 :(得分:2)
我认为,您的cloud api需要一些时间来获取AuthenticatedUser,因此您可以在回调方法中使用api完成事件。或者您可以将Action定义为回调,然后绑定属性。
答案 1 :(得分:0)
创建User
属性实现NotifyPropertyChanged
,然后在您的XAML绑定到User.Name
。这应该有用。
或者,您可以在设置NotifyPropertyChanged
属性后手动为Name
调用User
。