Articles :: View

How to Bind XAML to an Enum Description

How to Bind XAML to an Enum Description

XAML

xmlns:converters="clr-namespace:Your.Converters"

<UserControl.Resources>
    <converters:EnumDescriptionConverter x:Key="EnumDescriptionConverter"></converters:EnumDescriptionConverter>
</UserControl.Resources>

            <ComboBox ItemsSource="{Binding StoreSettings.PaymentFrequencyList}"
                        SelectedItem="{Binding StoreSettings.storeSettings.PaymentFrequency}"
                        Grid.Column="2" Grid.Row="2" VerticalAlignment="Center"
                        FontSize="20">
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <ComboBoxItem Content="{Binding Converter={StaticResource EnumDescriptionConverter}}"></ComboBoxItem>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>

VM

PaymentFrequencyList = new List<PaymentFrequency>();
PaymentFrequencyList = Enum.GetValues(typeof(PaymentFrequency))
                           .Cast<PaymentFrequency>()
                           .ToList();


Comments

Be the first to add a comment!