views:

106

answers:

1

I have a ListView with a GridView that's bound to the properties of a class that implements INotifyPropertyChanged, like this:

<ListView Name="SubscriptionView" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="2" ItemsSource="{Binding Path=Subscriptions}">
    <ListView.View>
        <GridView>
            <GridViewColumn Width="24" CellTemplate="{StaticResource IncludeSubscriptionTemplate}"/>
            <GridViewColumn Width="150" DisplayMemberBinding="{Binding Path=Name}" Header="Subscription"/>
            <GridViewColumn Width="75" DisplayMemberBinding="{Binding Path=RecordsWritten}" Header="Records"/>
            <GridViewColumn Width="Auto" CellTemplate="{StaticResource FilenameTemplate}"/>
        </GridView>
    </ListView.View>
</ListView>

The class looks like this:

public class Subscription : INotifyPropertyChanged
{
    public int RecordsWritten
    {
        get
        {
            return _records;
        }
        set
        {
            _records = value;
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs("RecordsWritten"));
        }
    }
    private int _records;

    ...
}

So I fire up a BackgroundWorker and start writing records, updating the RecordsWritten property and expecting the value to change in the UI, but it doesn't. In fact, the value of PropertyChanged on the Subscription objects is null. This is a puzzler, because I thought WPF is supposed to subscribe to the PropertyChanged event of data objects that implement INotifyPropertyChanged. Am I doing something wrong here?

+1  A: 

Figured out the problem. The "Subscriptions" list was coming from a LINQ query. When I added .ToList() to the end of that query, the UI started updating properly.

C. Lawrence Wenham