Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Binding ComboBox to enum
Message
From
18/12/2012 03:44:30
 
 
To
17/12/2012 13:23:04
General information
Forum:
ASP.NET
Category:
Windows Presentation Foundation (WPF)
Miscellaneous
Thread ID:
01559922
Message ID:
01559969
Views:
58
>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....
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform