GridViewColumn not subscribing to PropertyChanged event in a ListView

Posted by Chris Wenham on Stack Overflow See other posts from Stack Overflow or by Chris Wenham
Published on 2010-04-07T14:44:52Z Indexed on 2010/04/07 14:53 UTC
Read the original article Hit count: 429

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?

© Stack Overflow or respective owner

Related posts about .net-3.5

Related posts about wpf