As I stated in an earlier post, I will have a very common scenarion where I will have a ComboBox for picking a Customer from the list and binding that back to the database in a ForeignKey field. I will have this on over a dozen data input forms. I will also have lots more combos for picking other things (Vendords, Employees, etc)
So, I want to think about the best practice for populating ComboBoxes so that I do not have a lot of redundent code in the code-behind on all my forms.
Presently, I only have one form designed so far, and the ItemsSource property is established in the Constructor of the Window. But going forward, I want to have a class library or some strategy so that I have all this wired up already, that I just "drop" (or code) onto a form in a less hard-coding kind of way.
The ItemsSource will come from a very simple Linq call:
IEnumerable<Customer> custs = from a in ctx.Customers
select a;
dropdownJobStatus.ItemsSource = custs; //Set the UI
Then here is the XAML:
<ComboBox x:Name="dropdownJobStatus" Width="113" IsSynchronizedWithCurrentItem="True" AllowDrop="True"
DisplayMemberPath="company" SelectedValuePath="custno" SelectedValue="{Binding Path=cust_num}"/>