Silverlight 数据绑定到对象的属性

发布于 2024-10-12 16:55:31 字数 860 浏览 1 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

相思故 2024-10-19 16:55:31

如果我正确理解你的描述,它应该按照你的场景需要工作。但是,我在这里看到一个严重的问题:

    if (value != _agentExceptionDetail)
    {
      RaisePropertyChanged("AgentExceptionDetail");
      _agentExceptionDetail = value;
    }

您在实际更改任何内容之前就发送了更改通知!颠倒操作顺序即可纠正此错误。

    if (value != _agentExceptionDetail)
    {
      _agentExceptionDetail = value;
      RaisePropertyChanged("AgentExceptionDetail");
    }

It should work as you need in your scenario, if I understand your description right. However, I see a serious problem right here:

    if (value != _agentExceptionDetail)
    {
      RaisePropertyChanged("AgentExceptionDetail");
      _agentExceptionDetail = value;
    }

You are sending your change notification before you actually change anything! Reverse the order of operations to correct this error.

    if (value != _agentExceptionDetail)
    {
      _agentExceptionDetail = value;
      RaisePropertyChanged("AgentExceptionDetail");
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文