Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The best I can think of is to add an attached behavior which disables this with reflection once the Button has Loaded. I don't know if you like this better than to re-template it, but you won't have to include PresentationFramework.Aero and its re-usable</p> <pre><code>&lt;Button behaviors:DisableButtonChromeBehavior.DisableButtonChrome="True" ...&gt; &lt;Button.Style&gt; &lt;Style TargetType="Button"&gt; &lt;Setter Property="Background" Value="LightGreen"/&gt; &lt;Style.Triggers&gt; &lt;Trigger Property="IsMouseOver" Value="true"&gt; &lt;Setter Property="Background" Value="Green"/&gt; &lt;/Trigger&gt; &lt;Trigger Property="IsPressed" Value="true"&gt; &lt;Setter Property="Foreground" Value="DarkGreen"/&gt; &lt;/Trigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;/Button.Style&gt; &lt;/Button&gt; </code></pre> <p>The DisableButtonChromeBehavior</p> <pre><code>public static class DisableButtonChromeBehavior { public static readonly DependencyProperty DisableButtonChromeProperty = DependencyProperty.RegisterAttached ( "DisableButtonChrome", typeof(bool), typeof(DisableButtonChromeBehavior), new UIPropertyMetadata(false, OnDisableButtonChromePropertyChanged) ); public static bool GetDisableButtonChrome(DependencyObject obj) { return (bool)obj.GetValue(DisableButtonChromeProperty); } public static void SetDisableButtonChrome(DependencyObject obj, bool value) { obj.SetValue(DisableButtonChromeProperty, value); } private static void OnDisableButtonChromePropertyChanged(DependencyObject dpo, DependencyPropertyChangedEventArgs e) { Button button = dpo as Button; if (button != null) { if ((bool)e.NewValue == true) { button.Loaded += OnButtonLoaded; } else { button.Loaded -= OnButtonLoaded; } } } private static void OnButtonLoaded(object sender, RoutedEventArgs e) { Button button = sender as Button; Action action = () =&gt; { object buttonChrome = VisualTreeHelper.GetChild(button, 0); Type type = buttonChrome.GetType(); PropertyInfo propertyInfo = type.GetProperty("RenderMouseOver"); if (propertyInfo != null) { propertyInfo.SetValue(buttonChrome, false, null); propertyInfo = type.GetProperty("RenderPressed"); propertyInfo.SetValue(buttonChrome, false, null); propertyInfo = type.GetProperty("RenderDefaulted"); propertyInfo.SetValue(buttonChrome, false, null); } }; button.Dispatcher.BeginInvoke(action, DispatcherPriority.ContextIdle); } } </code></pre> <p><strong>Update</strong><br> There's also the shorter non re-usable way, just doing this in code behind.</p> <pre><code>private void Button_Loaded(object sender, RoutedEventArgs e) { Button button = sender as Button; object buttonChrome = VisualTreeHelper.GetChild(button, 0); PropertyInfo renderMouseOverInfo = buttonChrome.GetType().GetProperty("RenderMouseOver"); if (renderMouseOverInfo != null) { renderMouseOverInfo.SetValue(buttonChrome, false, null); } } </code></pre> <p>Or (if you don't mind including Aero)</p> <pre><code>&lt;Button ...&gt; &lt;Button.Resources&gt; &lt;Style TargetType="Microsoft_Windows_Themes:ButtonChrome"&gt; &lt;EventSetter Event="Loaded" Handler="ButtonChrome_Loaded"/&gt; &lt;/Style&gt; &lt;/Button.Resources&gt; void ButtonChrome_Loaded(object sender, RoutedEventArgs e) { ButtonChrome buttonChrome = sender as ButtonChrome; if (buttonChrome != null) { buttonChrome.RenderMouseOver = false; buttonChrome.RenderPressed = false; } } </code></pre> <p>Other than that, I think you don't have any other outs than the solution you pointed yourself (re-templating).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload