当项目添加到绑定集合时,WPF - UI未更新

当项目添加到绑定集合时,WPF - UI未更新

问题描述:

我有一个通用的绑定到自定义控件的对象的列表。在代码隐藏方面,一切似乎都行得通,但我对集合所做的任何更改似乎都不反映在UI中(即使它们在所有代码中都可以找到)。当项目添加到绑定集合时,WPF - UI未更新

下面是我的UI的XAML:

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

背后,我添加项目到集合代码:

_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 

中的ItemSource属性在我的用户控件:

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); 
    } 
} 

最后,一个标准ListView的XAML位于我的用户控件中,它是绑定的上面列出的ItemsSource属性:

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

只是重申,一切工作正常,当我周围显示采集的第一次,但是当我将项目添加到集合,用户界面不会反映所做的更改。

由于提前,
桑尼

+0

是什么类型_caseScreen.CaseEvents? – 2010-12-15 00:58:08

更改您的收藏ObservableCollection<T>

+0

非常好。谢谢。 – 2010-12-15 01:13:09