views:

350

answers:

3

I've a TextBlock that looks like so:

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

This is inside a <Canvas> with the DataContext set to MyClient which is in the ViewModel:

public Client MyClient { get; private set; } // This is a RIA Entity, hence supports INotifyPropertyChanged

public ViewModel() {
    MyClient = new Client();
    LoadOperation<Client> loadClient = RiaContext.Load<Client>(RiaContext.GetClientsQuery());
    loadClient.Completed += new EventHandler(loadClient_Completed);
}

void loadClient_Completed(object sender, EventArgs e) {
    MyClient = DB.Clients.Single();
}

Setting MyClient like the above does not raise the PropertyChanged event. As such the UI is never updated.

A: 

Here's what I ended up doing. I added an event which is triggered when the RIA callback is complete. I then attach a handler to this in the view which sets the DataContext to the ViewModel. So effectively, it waits until the ViewModel has grabbed the data, and then it sets the DataContext to the ViewModel - thus getting the correct data.

DaRKoN_
A: 

You should set OneWay or TwoWay binding.

<TextBlock Text="{Binding Name, Mode=OneWay}" />
<TextBlock Text="{Binding Name, Mode=TwoWay}" />

By default I believe binding does OneTime.

Tacoman667
A: 

The UI never updates because you are replacing the object the UI is attached to. The replacement happens on the loadClient_completed method.

Klinger