Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Best practice for populating ComboBox ItemsSource?
Message
De
14/07/2008 17:02:07
 
 
À
14/07/2008 13:19:53
Information générale
Forum:
ASP.NET
Catégorie:
Windows Presentation Foundation (WPF)
Divers
Thread ID:
01331114
Message ID:
01331225
Vues:
9
>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}"/>
>
I would just subclass a combobox for this and put the linq in the constructor.

You will also want a dependency property the implement the binding on the key field.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform