私はこのコンボをlinqテーブルにバインドしました。 linqテーブルに新しいレコードを挿入すると、UI(ユーザーに表示されるコンボの値)を軽量に更新できますか?System.Data.Linq.TableへのWPFデータバインディング<T>、インターフェイスの更新方法は?
基本的に私はObservableCollectionを使用していたはずですが、データをのlinqテーブルからそのコレクションにコピーしたくないので、linqテーブルにデータを入れたいだけです。
これは可能ですか?ここで
EDIT
OKは私がやっていることである(そしてまだそれが動作しません):XAMLで
private ObservableCollection<Categories> m_Categories;
private ObservableCollection<Categories> Categories
{
get
{
return m_Categories;
}
}
私が持っている:
だから、 <ComboBox Name="cmbCategory"
ItemsSource="{Binding Categories}"
DisplayMemberPath="Name"
SelectedValuePath="Id"
/>
、ものすごく単純。
//if i have a new category, i want to update the combo's content
if (frmEditCategory.ShowDialog() == true)
{
//get the new category and add it to the ObservableCollection
LibraryDataStore.Instance.Categories.ToList().ForEach(p =>
{
if (!m_Categories.Contains(p))
{
m_Categories.Add(p);
}
});
//update the target? is this correct?!
BindingExpression be = cmbCategory.GetBindingExpression(ComboBox.ItemsSourceProperty);
if (be != null)
be.UpdateTarget();
}
デバッガでチェックされているm_Categoriesには新しいカテゴリが含まれていますが、コンボには表示されません。また
は、コンボ結合についての良いチュートリアルやブログ記事を知っていますか?...
は何を求めていることはできません事前
はい、正しく、ObservableCollectionを使用しようとしています。 – Teodor
...それは動作し、実装するのはそれほど難しくありません。 – Teodor