Question

I have a Silverlight ModelViewViewModel project that I would like to expose a property on the view model to a UserControl like:

public DTO.Client Client
{
    get { return client; }
}

client is a private backing variable that I set in a async completed event handler:

    void GetClientByIDComplete(object sender, GetClientByIDCompletedEventArgs e)
    {
        Application.Current.RootVisual.Dispatcher.BeginInvoke(() =>
        {
            DTO.Client c = new ServiceContract.DTO.Client();
            c = e.Result as DTO.Client;
            client = e.Result as DTO.Client;
        });
    }

In my Silverlight page I have the following:

<TextBlock Text="{Binding Client.Name}"/>

The data never is displayed. The data is displayed if I change the property to:

public DTO.Client Client
{
    get { 
          client.Name = "My Name";
          return client; }
}

This way I explicitly assign the value.

What do I have to change so the property is seen by my page?

Was it helpful?

Solution

Are you setting the data context after Client is populated, or before?

After it should definately display, before, it will not know the underlying data has changed without adding additional code, implement INotifyPropertyChanged so that bindings can understand the data has altered.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top