开发者

WPF - UI Not Updating When Item Added to Bound Collection

I have a Generic List of objects that I've bound to a custom control. Everything seems to work OK in the code-behind, but any changes I make to the collection don't seem to reflect in the UI (even though they're working find in all the code behind).

Here's the XAML for my UI:

<controls:ControllableListView x:Name="lvSummaryCaseEvents" Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="3" Label="Case Events:" ItemsSource="{Binding CaseEvents}" AddButtonClicked="ControllableListView_AddButtonClicked">

And the code behind where I add the item into the collection:

_caseScreen.CaseEvents.Add(caseEvent);
//after the line above executes, lvSummaryCaseEvents (in the debugger) shows the correct number of items and the items' values are all correct.  No change to the UI whatsoever

The ItemSource property in my user control:

public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.Register("ItemsSource", typeof(System.Collections.IList), typeof(ControllableListView));

public System.Collections.IList ItemsSource
{
    get
    {
        return this.GetValue(ItemsSourceProperty) as System.Collections.IList;
    }
    set
    {
        this.SetValue(ItemsSourceProperty, value);
    }
}

And finally, the XAML for a standard ListView that lives in my user contro开发者_开发百科l which is bound to the ItemsSource property listed above:

<ListView Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="4" Name="lvListView" ItemsSource="{Binding ItemsSource}" View="{Binding View}" SelectionChanged="lvListView_SelectionChanged" />

Just to reiterate, everything works fine when I display the collection the first time around, but when I add an item to the collection, the UI does not reflect the changes made.

Thanks in advance,

Sonny


Change your collection to ObservableCollection<T>

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜