开发者

Silverlight DataBinding to properties of object

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 p开发者_运维技巧opup 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?


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");
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜