Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Binding ComboBox to enum
Message
De
18/12/2012 03:44:30
 
 
À
17/12/2012 13:23:04
Information générale
Forum:
ASP.NET
Catégorie:
Windows Presentation Foundation (WPF)
Divers
Thread ID:
01559922
Message ID:
01559969
Vues:
57
>Hi,
>
>I have the following enum defined:
>
>
        public enum RateType : int
>        {
>            Standard = 1,
>            Mail = 2,
>            ZipX = 3
>        }
>
>I need to let the user pick form a combo whether the rate is one of these (standard, Mail or ZipX) and store the int value back to the database.
>
>How would I define this in xaml?
>
>Something like this:
>
>
<ComboBox Grid.Column="1" Grid.Row="1" Margin="0" Name="cboRateTypes" SelectedValue="{Binding rat_type, Mode=Default}" VerticalAlignment="Center" ItemsSource="{Binding}">
>                                    <ComboBoxItem Content="Standard" />
>                                    <ComboBoxItem Content="Mail" />
>                                    <ComboBoxItem Content="ZipX" />
>                                </ComboBox>
MarkupExtension is one way to go. The first answer here gives an example which would work with any enum:
http://stackoverflow.com/questions/58743/databinding-an-enum-property-to-a-combobox-in-wpf

Or using ObjectDataProvider:
http://www.codeproject.com/Articles/29495/Binding-and-Using-Friendly-Enums-in-WPF

Both may look more complex than what you are looking for but will be useful again and again....
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform