Fermin
Fermin

Reputation: 36111

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 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?

Upvotes: 0

Views: 419

Answers (1)

Sander
Sander

Reputation: 26374

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

Upvotes: 2

Related Questions