title: WPF Visibility Binding to Converted Instance Property
body: <p>So I have a button. I want to set the visibility of the button according to the value of an integer property of a class. This requires a data binding and a converter.</p>
  
  <p>The XAML code for the button is as follows:</p>
  
  <pre><code>&lt;Window.Resources&gt;
          &lt;local:Button1VisibilityConverter x:Key="Button1VisibilityConverter"/&gt;
          &lt;local:ModeValues x:Key="ModeHolder"/&gt;
      &lt;/Window.Resources&gt;
      &lt;Grid&gt;
          &lt;StackPanel HorizontalAlignment="Left" Height="150" Margin="92,90,0,0" VerticalAlignment="Top" Width="301"&gt;
              &lt;Button Content="1" Height="58" Background="#FFA20000" Foreground="White" Visibility="{Binding Source={StaticResource ModeHolder}, Path=State, Converter=Button1VisibilityConverter}"/&gt;
              &lt;Button Content="2" Height="58" Background="#FF16A200" Foreground="White"/&gt;
              &lt;Button Content="3" Height="58" Background="#FF4200A2" Foreground="White"/&gt;
          &lt;/StackPanel&gt;
      &lt;/Grid&gt;
  </code></pre>
  
  <p>My converter is as follows:</p>
  
  <pre><code>class Button1VisibilityConverter : IValueConverter
      {
          public object Convert(object value, Type targettype, object parameter, System.Globalization.CultureInfo culture)
          {
              int mode = (int)value;
              if (mode == ModeValues.Red)
                  return System.Windows.Visibility.Visible;
              else
                  return System.Windows.Visibility.Collapsed;
          }
  
          public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
          {
              return null;
          }
      }
  </code></pre>
  
  <p>The class that has the property I want to control the visibility is as follows:</p>
  
  <pre><code>public class ModeValues : IObservable&lt;int&gt;
      {
          private int _state = -1;
  
          public static int Red
          {
              get
              {
                  return 0;
              }
          }
  
          public static int Green
          {
              get
              {
                  return 1;
              }
          }
  
          public static int Purple
          {
              get
              {
                  return 2;
              }
          }
  
          public int State
          {
              get
              {
                  return this._state;
              }
              set
              {
                  this.State = value;
              }
          }
      }
  </code></pre>
  
  <p>I have no idea why it isn't working. I thought I had to bind the visibility to the property of the instance of the ModeHolder, make the ModeHolder observable, and convert the int to a visibility. What am I missing?</p>