title: How to change the roundness of a button in a generic way
body: <p>I am currently working on making my WPF application a little bit more generic.
  Up to this point, for each button I wanted to create, I used a different style to modify roundness (and it creates a lot of useless code).</p>
  <p><strong>Using the following code</strong> I've managed to create a variable I can change from the XAML file, but I cannot link it to the roundness itself.</p>
  <p>Could anyone please tell me what I am doing wrong? I already have checked on so many forums but no one seems to have the answer other than &quot;don't do it in a generical way&quot;.</p>
  <p><em>I can precise that everything is compiling and the style is otherwise correctly applied to the button (there is no xaml linking problem).</em></p>
  <p><strong>The style I am using:</strong></p>
  <pre><code>&lt;Style x:Key=&quot;AwakeButton&quot; TargetType=&quot;{x:Type customcontrols:AwakeButton}&quot; BasedOn=&quot;{StaticResource {x:Type Button}}&quot;
         xmlns:extensions=&quot;Awake.Services.Properties:Extensions&quot;&gt;
      &lt;Setter Property=&quot;customcontrols:AwakeButton.BorderRoundness&quot; Value=&quot;4.0&quot;/&gt;
      &lt;Style.Resources&gt;
          &lt;Style TargetType=&quot;Border&quot;&gt;
              &lt;Setter Property=&quot;CornerRadius&quot; Value=&quot;{Binding Path=BorderRoundness}&quot; /&gt;
              &lt;!--&lt;Setter Property=&quot;CornerRadius&quot; Value=&quot;10&quot; /&gt;--&gt;
          &lt;/Style&gt;
      &lt;/Style.Resources&gt;
  &lt;/Style&gt;
  </code></pre>
  <p><strong>The overload of the button I created to do so:</strong></p>
  <pre><code>public class AwakeButton : Button
  {
      public AwakeButton()
      {
          
      }
  
      public static DependencyProperty BorderRoundnessProperty =
           DependencyProperty.RegisterAttached(&quot;BorderRoundness&quot;, typeof(double), typeof(AwakeButton)); 
      public static void SetBorderRoundness(UIElement element, double value)
      {
          element.SetValue(BorderRoundnessProperty, value);
          
      }
  
      public static double GetBorderRoundness(UIElement element)
      {
          return (double)element.GetValue(BorderRoundnessProperty);
      }
  }
  </code></pre>
  <p><strong>How I am using it in the page:</strong></p>
  <pre><code>&lt;customcontrols:AwakeButton Style=&quot;{StaticResource AwakeButton}&quot; Margin=&quot;142,115,0,0&quot;  Width=&quot;136&quot; Height=&quot;167&quot; BorderRoundness=&quot;5&quot;&gt;
  </code></pre>