title: How to add a DependencyProperty to a Button?
body: <p>I'm basically just trying to add a couple properties to a button to store some extra information to be used later. My choice to do this instead of creating a UserControl based on a Button was solely because it seemed like less code.</p>
  
  <p>I've followed the examples I've seen on Microsoft's site and I'm getting the error "A 'Binding' cannot be set on the 'SetSortIndicatorVisibility' property of type 'Button'. A 'Binding' can only be set on a DependencyProperty of a DependencyObject." It doesn't make sense because a Button is a DependencyObject and I'm adding a DependencyProperty. I initially started with an AttachedProperty but I've since fixed that. I've even taken all my code that relates to this and put it in a test project and I'm still getting this error. All of this test code is below:</p>
  
  <p>DependencyProperty Definition:</p>
  
  <pre><code>public static readonly DependencyProperty SortIndicatorVisibilityProperty = DependencyProperty.Register( "SortIndicatorVisibility", typeof( Visibility ), typeof( Button ), new FrameworkPropertyMetadata( Visibility.Visible, FrameworkPropertyMetadataOptions.AffectsRender ) );
  
      public static void SetSortIndicatorVisibility( Button button, Visibility value )
      {
          button.SetValue( SortIndicatorVisibilityProperty, value );
      }
      public static Visibility GetSortIndicatorVisibility( Button button )
      {
          return ( Visibility ) button.GetValue( SortIndicatorVisibilityProperty );
      }
  </code></pre>
  
  <p>Window XAML containing the button with the new property and the binding:</p>
  
  <pre><code>&lt;Window x:Class="Testing.MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:ext="clr-namespace:Testing"
      Title="MainWindow" Height="350" Width="525"&gt;
  &lt;Grid&gt;
      &lt;Button Content="Test"
              Command="{Binding TestCommand}"
              ext:Class1.SortIndicatorVisibility="{Binding SortIndicatorVisibilitySiteName}" /&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p>
  
  <p>Lastly, the property the DependencyProperty is bound to:</p>
  
  <pre><code>public Visibility SortIndicatorVisibilitySiteName
      {
          get
          {
              return Visibility.Visible;
          }
      }
  </code></pre>