WPF data binding to System.Data.Linq.Table <T> how to update the interface?

I have this combination bound to linq table. Is there a lightweight way to update the user interface (combo values ​​that are displayed to the user) when I insert a new record into the linq table?

Mostly from what I understand, I had to use an ObservableCollection, but I don't want to copy the data back and forth from the linq table to this collection, I only want to have the data in the linq table.

Is it possible?

EDIT

OK Here is what I did (and still not working):

    private ObservableCollection<Categories> m_Categories;
    private ObservableCollection<Categories> Categories
    {
        get
        {
            return m_Categories;
        }
    }

in xaml i:

                 <ComboBox Name="cmbCategory" 
                           ItemsSource="{Binding Categories}"
                           DisplayMemberPath="Name"
                           SelectedValuePath="Id"
                           />

So, pretty simple.

       //if i have a new category, i want to update the combo 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();     
        }

Checked using the debugger, m_Categories contains a new category, but does not appear in combos.

Also, do you know a good tutorial or blog post about combo binding? ...

Thank you in advance

+3
1

, , . - , ObservableCollection. Linq -, , . ObservableCollection, Linq, ObservableCollection, . , , .

+2

Source: https://habr.com/ru/post/1715627/


All Articles