title: Data binding Int property to Enum in WPF
body: <p>Below is a simplified example of a class I have:</p>
  
  <pre><code>public class ExampleClassDto 
  {
       public int DriverTypeId
  }
  </code></pre>
  
  <p>I also have an Enum that maps the Ids of DriverType to meaningful names:</p>
  
  <pre><code>public enum DriverType
  {
      None,
      Driver1,
      Driver2,
      Driver3
  }
  </code></pre>
  
  <p>But I want to bind this in XAML to a combobox. Unfortunately, because of the type mismatch, it doesn't like this. So in my ViewModel, I have to create a second property to map the two</p>
  
  <pre><code>public class ExampleViewModel
  {
      private ExampleClassDto _selectedExampleClass;
      public ExampleClassDto SelectedExampleClass
      {
          get { return _selectedExampleClass; }
          set
          {
              _selectedExampleClass = value;
              SelectedDriverType = (DriverType)_selectedExampleClass.DriverTypeId;
              OnPropertyChanged("SelectedDeviceType");
          }
      }
  
  public DriverType SelectedDriverType
  {
      get
          {
              if (_selectedDeviceType != null) 
              { 
                  return (DriverType)_selectedDeviceType.DriverTypeId;
              }
              return DriverType.None;
          }
          set
          {
              _selectedDeviceType.DriverTypeId = (int) value;
              OnPropertyChanged("SelectedDriverType");
          }
  }
  }
  </code></pre>
  
  <p>Then I bind to the new property.</p>
  
  <pre><code>&lt;ComboBox ItemsSource="{Binding Source={StaticResource DriverTypeEnum}}" SelectedValue="{Binding SelectedDriverType, Mode=TwoWay}"/&gt;
  </code></pre>
  
  <p>Now, this WORKS, but feels very gross. It's using SelectedDriverType as a converter. I want to avoid having to make the DTO's property a different type. Are there other, more elegant, solutions?</p>
  
  <p>Thanks!</p>