我有WPF ListView綁定到ObservableCollection。更改項目時,WPF ListView不會更新DisplayMemberPath MVVM
這裏是我的ListView:
<ListView
BorderBrush="#6797c8"
BorderThickness="2"
ItemsSource="{Binding Path=MainCategoriesCollection, UpdateSourceTrigger=PropertyChanged}"
DisplayMemberPath="Category"
SelectedValuePath="MainCatID"
SelectedItem="{Binding MainCategorySelectedItem}"
SelectedIndex="{Binding MainCategorySelectedIndex, Mode=TwoWay}"
FontSize="14"/>
,這是我的ItemSource:
private ObservableCollection<DataModel.MainCategories> mainCategoriesCollection;
public ObservableCollection<DataModel.MainCategories> MainCategoriesCollection
{
get
{
if (mainCategoriesCollection == null)
{
mainCategoriesCollection = new ObservableCollection<DataModel.MainCategories>();
}
return mainCategoriesCollection;
}
set
{
mainCategoriesCollection = value;
RaisePropertyChanged("MainCategoriesCollection");
}
}
我了有線問題。當我從MainCategoriesCollection添加項目或刪除項目我的ListView得到更新沒有任何問題,但是當我採取具體項目,並更改代表「DisplayMemberPath」的項目屬性時,我看不到ListView中的更改。我調試了這個問題,看到MainCategoriesCollection中存在的變化,但是我的ListView拒絕顯示它。
任何想法?
調試綁定問題的最佳方法通常只是在Visual Studio的輸出窗口中查找綁定錯誤 – ghord 2013-03-04 18:46:41
無需INPC您的可觀察集合屬性。 – Will 2013-03-05 16:07:59
如果您實例化一個新的ObservableCollection,綁定仍然會在沒有INPC的情況下更新嗎? – 2013-03-05 22:04:32