title: How to set Button.Style to x:Static resource from code behind in WPF?
body: <p>I need to call static resource for button style in code-behind using C#  </p>
  
  <p>This is my Button in XAML:</p>
  
  <pre><code>&lt;Button Height="48" HorizontalAlignment="Left" Margin="229,0,0,0" Name="btnlogin" 
          VerticalAlignment="Top" Width="90" Grid.Row="6" BorderThickness="0" 
          MouseEnter="btnlogin_MouseEnter" MouseLeave="btnlogin_MouseLeave" 
          BorderBrush="Transparent" 
          Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"&gt;
      &lt;Button.Background&gt;
          &lt;ImageBrush ImageSource="/BaccaratDealerInterfaceWPF;component/Images/Login_Button_Normal.png" /&gt;
      &lt;/Button.Background&gt;
  &lt;/Button&gt;
  </code></pre>
  
  <p>I need to set this <code>Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"</code>  to <code>btnlogin.Style</code> property in code behind C#.</p>
  
  <p>I've tried</p>
  
  <pre><code> Style style = this.FindResource("{x:Static ToolBar.ButtonStyleKey}") as Style;
   btnlogin.Style = style;
  </code></pre>