Search code examples
wpfdata-bindinglinq-to-sqlmodel-bindingdatacontext

WPF - how to use multiple data context for binding


Please note: I have used Linq to SQL classes.so I have all my models created automatically

I have window that adds new products .so I have binded the controls on the form to Product Properties

this.DataContext =new tbl_Product();

Now I have some combo boxes on the same window like category n type I populate my combo boxes binding the item source to tbl_Category n tbl_Type

Now my issue is that I can only give one model as data context .if I give tbl_Category as data context I can't add products or if I give tbl_Products as data context then my combo boxes don't get populated.

Plz help me.Thanks in advance.


Solution

  • Set the datacontexts of the individual comboboxes to the required contexts rather that setting the data context at window level