title: Bind Image to ComboBox based on Object Enum Value
body: <p>I have a Character Class that has an property Gender that is an Enum. What I want my code to do is to switch images based on what gender my Character is(if the character is male = male image). </p>
  
  <p>Where I am having the problem is how to correctly access and get this Enum value. You see, I am creating an ObservableCollection of type Character. I am then binding this collection to a ComboBox and then displaying the DisplayMemberPath via the ItemTemplate. </p>
  
  <p>I believe I am doing all the binding right, but I am not accessing the Character Gender property correctly in my value converter. </p>
  
  <p><strong>The XAML:</strong> Referencing the Converter &amp;&amp; ComboBox</p>
  
  <pre><code>xmlns:converters="clr-namespace:ImageViaGenderTest_2014"
  Title="MainWindow" Height="350" Width="1004.932"&gt;
  &lt;Window.Resources&gt;
      &lt;converters:GenderToIconFilenameConverter x:Key="IconConverter"/&gt;
  &lt;/Window.Resources&gt;
  
  
   &lt;ComboBox x:Name="Character_ComboBox" HorizontalAlignment="Left" VerticalAlignment="Top" Width="328" Height="25"&gt;
              &lt;ComboBox.ItemTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;StackPanel Orientation="Horizontal"&gt;
                          &lt;TextBlock Width="50" Text="{Binding Name}"/&gt;
                          &lt;TextBlock Width="50" Text="{Binding Level}"/&gt;
                          &lt;Image Source="{Binding Gender, Converter={StaticResource IconConverter}}"/&gt;
                      &lt;/StackPanel&gt;
                  &lt;/DataTemplate&gt;
              &lt;/ComboBox.ItemTemplate&gt;
          &lt;/ComboBox&gt;
  </code></pre>
  
  <p><strong>The Observable Collection Setup in MainWindow</strong></p>
  
  <pre><code>  public ObservableCollection&lt;Character&gt; squad_members = new ObservableCollection&lt;Character&gt;();
  
      public MainWindow()
      {
          InitializeComponent();
  
          squad_members.Add(new Character() { Name = "john_snow_knows_nothing", Level = 8,  _Gender = Gender.Male});
          squad_members.Add(new Character() { Name = "Ygritt_gets_wrecked", Level = 4,  _Gender = Gender.Female});
  
          Binding comboBinding = new Binding();
          comboBinding.Source = squad_members;
  
          BindingOperations.SetBinding(Character_ComboBox, ComboBox.ItemsSourceProperty, comboBinding);
      }
  </code></pre>
  
  <p><strong>The Custom Value Converter Class(Where I think I'm referencing the Gender Enum incorrectly) ERROR AREA:</strong> </p>
  
  <pre><code>[ValueConversion(typeof(Gender), typeof(Image))]
  public class GenderToIconFilenameConverter : IValueConverter
  {
  
      public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
      {
              switch ((Gender)value)
              {
                  case Gender.Female:
                      return "character1.jpg";
                  case Gender.Male:
                      return "character2.jpg";
                  default:
                      return null;
              }
  
      }
  
      public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
      {
          throw new NotSupportedException();
      }
  }
  </code></pre>
  
  <p><strong>Character Class:</strong></p>
  
  <pre><code>public class Character 
  {
      public string Name { get; set; }
      public int Level { get; set; }
      public Gender _Gender { get; set; }
  }
  </code></pre>
  
  <p><strong>Gender Enum:</strong></p>
  
  <pre><code>public enum Gender
  {
      Male, Female
  }
  </code></pre>
  
  <p>Am i referencing my Character Gender enum incorrectly? Or is there something else I forgot?
  I also got help from this question:
  <a href="https://stackoverflow.com/questions/2786792/bind-icon-depending-on-enum-in-wpf-treeview">Bind Icon depending on Enum in WPF Treeview</a> </p>