siger
siger

Reputation: 3162

Silverlight/Windows Phone ViewModel updating question

I have a XAML page whose DataContext is set to my ViewModel. A switch control on the page is bound to the following code in the ViewModel:

public bool TeamLiveTileEnabled
{
    get
    {
        return Data.Subscriptions.Any(s => s.TeamName == this.Team.Name);
    }
}

When this page is initialized, Data.Subscriptions is an empty list. I retrieve the list of subscriptions through an async web service call, so it comes back after the getter above is called.

When the web service call comes back, Data.Subscriptions has items added to it, and I'd like the UI to update based on the new result of the LINQ expression. Right now nothing happens, and I confirmed that Data.Subscriptions contains items that satisfy the condition above.

Data.Subscriptions is an ObservableCollection of Subscription items.

Can someone point me to what to do? Thanks!

Upvotes: 0

Views: 368

Answers (1)

Praetorian
Praetorian

Reputation: 109089

The problem is that your ViewModel is not aware of any changes to the ObservableCollection. Within the ViewModel, subscribe to the CollectionChanged event of Data.Subscriptions.

Data.Subscriptions.CollectionChanged += SubscriptionsChangedHandler;

Within the event handler notify listeners of TeamLiveTileEnabled by sending a PropertyChanged notification

NotifyPropertyChanged( "TeamLiveTileEnabled" );

Upvotes: 1

Related Questions