Silverlight 数据绑定到对象的属性
我有一个 silverlight ChildWindow。当我单击链接时,它会打开此子窗口并显示 ViewModel 中的一些数据。问题是当 ViewModel 中的数据更新时,它不会更新。
弹出窗口中的示例:
<TextBox Text="{Binding Path=AgentExceptionDetail.Action, Mode=TwoWay}" />
ViewModel:
private AgentExceptionDetail _agentExceptionDetail;
public AgentExceptionDetail AgentExceptionDetail
{
get { return _agentExceptionDetail; }
set
{
if (value != _agentExceptionDetail)
{
RaisePropertyChanged("AgentExceptionDetail");
_agentExceptionDetail = value;
}
}
}
此 AgentExceptionDetail 对象是通过调用 RIA-Services 填充的。这次调用成功,数据返回正常。绑定实际上的行为就像是 Mode=OneTime 而不是 OneWay,因为当我关闭并重新打开弹出窗口时,会显示数据,但弹出窗口第一次打开 AgentExceptionDetail=null 时,会在调用返回时填充数据。
当绑定实际上正在寻找“AgentExceptionDetail.Action”时,这是否与我引发“AgentExceptionDetail”的属性更改事件有关?如果是这样,有办法解决这个问题吗?
I have a silverlight ChildWindow. When I click on a link it opens this child window and displays some data from my ViewModel. The problem is this isn't updating when the data in the ViewModel is updated.
Sample from Popup:
<TextBox Text="{Binding Path=AgentExceptionDetail.Action, Mode=TwoWay}" />
ViewModel:
private AgentExceptionDetail _agentExceptionDetail;
public AgentExceptionDetail AgentExceptionDetail
{
get { return _agentExceptionDetail; }
set
{
if (value != _agentExceptionDetail)
{
RaisePropertyChanged("AgentExceptionDetail");
_agentExceptionDetail = value;
}
}
}
This AgentExceptionDetail object is populated via a call to RIA-Services. This call is successful and the data is brought back okay. The Binding is actually acting like it's Mode=OneTime rather than OneWay because when I close and re-open the popup the data is displayed but the first time the popup opens AgentExceptionDetail=null, being populated when the call comes back.
Is this to do with me raising a property changed event for "AgentExceptionDetail" when the binding is actually looking for "AgentExceptionDetail.Action"? If so is there a way round this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我正确理解你的描述,它应该按照你的场景需要工作。但是,我在这里看到一个严重的问题:
您在实际更改任何内容之前就发送了更改通知!颠倒操作顺序即可纠正此错误。
It should work as you need in your scenario, if I understand your description right. However, I see a serious problem right here:
You are sending your change notification before you actually change anything! Reverse the order of operations to correct this error.