title: Setting button flat style programmatically
body: <p>I want to give a button a flat style programmatically when certain conditions occur.</p>
  
  <p><a href="https://stackoverflow.com/questions/3199424/how-to-set-the-style-programatically">This question</a> shows how I can set a style to a control programmatically, having already defined it in XAML.</p>
  
  <p><a href="https://stackoverflow.com/questions/697381/setting-button-flatstyle-in-wpf">This question</a> shows that a flat button style already exists, so it is not necessary to create one in XAML.</p>
  
  <p><code>ToolBar.ButtonStyleKey</code> returns a <code>ResourceKey</code>, and the corresponding style is not defined in my window (it's in ToolBar). How do I use it in code to set the style programmatically?</p>