Telerik RadComboBox Bind To Enum

Rustam Safin Oct 15, 2014

The result you want to see:

TestCombobox.xaml

<Window x:Class="TelerikWpfApp1.TestComboBox"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
        xmlns:telerikWpfApp1="clr-namespace:TelerikWpfApp1"
        Title="TestComboBox" Height="300" Width="300">
    <Window.Resources>
        <telerik:EnumDataSource EnumType="telerikWpfApp1:PlayerType"
                                x:Key="enumDataSource" />
    </Window.Resources>
    <Grid>
        <telerik:RadComboBox SelectedValue="{Binding Path=PlayerType}"
                             ItemsSource="{Binding Source={StaticResource enumDataSource}}"
                             DisplayMemberPath="DisplayName"
                             SelectedValuePath="Value" />
    </Grid>
</Window>

TestCombobox.xaml.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows;
namespace TelerikWpfApp1
{
    public partial class TestComboBox
    {
        public TestComboBox()
        {
            InitializeComponent();
            this.DataContext = new Player()
            {
                PlayerType = PlayerType.Defender,
            };
        }
    }
    public enum PlayerType
    {
        [Description("The forward")]
        Forward,
        [Description("The defender")]
        Defender,
        [Description("The goal keeper")]
        GoalKeeper,
    }
    public class Player
    {
        public PlayerType PlayerType { get; set; }
    }
}
Rustam Safin

C# and Python developer