2013-03-04 171 views
2

我有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拒絕顯示它。

任何想法?

+2

調試綁定問題的最佳方法通常只是在Visual Studio的輸出窗口中查找綁定錯誤 – ghord 2013-03-04 18:46:41

+0

無需INPC您的可觀察集合屬性。 – Will 2013-03-05 16:07:59

+0

如果您實例化一個新的ObservableCollection,綁定仍然會在沒有INPC的情況下更新嗎? – 2013-03-05 22:04:32

回答

4

確保DisplayMemberPath屬性位於具有所有INotifyPropertyChanged內容的視圖模型上,即屬性observable?

+0

你說得對。謝謝 – Ofir 2013-03-04 19:01:19