2009-04-27 57 views
0

我已綁定列表框與此代碼的SQL CE數據庫:更新列表框

ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:DatabaseWindow}}, Path=Database.Photos1}" 

此列表框填充正確。但是,當我嘗試向數據庫插入一行(InsertOnSubmit + SubmitChagnes)時,ListBox不會更新!

我曾嘗試:

ListBox.Items.Refresh(); 

ListBox.GetBindingExpression(ListBox.ItemsSourceProperty).UpdateTarget(); 

ListBox.ItemsSource = null; 
ListBox.ItemsSource = this.Database.Table; 

的這些幫助無。我如何更新ListBox?

PS:重新加載數據庫後,該行出現在列表框中。PPS:如果有人知道使用WPF插入到ListBox的SQL CE的教程 - 那也太棒了!

回答

1

確保您分配給ItemsSource的數據實現INotifyCollectionChanged。 (例如,您可以將項目放入ObservableCollection中) 另外,要更改要反映的單個項目,您必須實施INotifyPropertyChanged。

+1

是的,我知道這就是ListBox不會自動更新*的原因。但是如果我可以手動更新它就足夠了。 – eWolf 2009-04-27 18:39:56