Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do you change TemplateBindings to Bindings in a button's control template, without repeating the whole control template
    text
    copied!<p>I want to change the background color of a button in its normal, moused-over and pressed states to various shades of green. I am forced to add the following grotesquely verbose <code>Button.Template</code> to my button so that I can modify the <code>RenderMouseOver</code> and <code>RenderPressed</code> attributes to use <code>Binding</code> instead of <code>TemplateBinding</code>, so that my triggers (in the <code>Button.Style</code>) actually take effect instead of being ignored due to the compile time nature of <code>TemplateBinding</code>. Is there anyway to override these two attributes more cleanly for an Aero theme than to repeat the entire template binding in its entirety? XAML follows:</p> <pre><code>&lt;Window x:Class="ButtonMouseOver.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"&gt; &lt;Grid&gt; &lt;Button&gt; Hello &lt;Button.Template&gt; &lt;ControlTemplate TargetType="{x:Type Button}"&gt; &lt;Microsoft_Windows_Themes:ButtonChrome SnapsToDevicePixels="true" x:Name="Chrome" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" RenderDefaulted="{TemplateBinding IsDefaulted}" RenderMouseOver="{Binding IsMouseOver}" RenderPressed="{Binding IsPressed}" &gt; &lt;ContentPresenter Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/&gt; &lt;/Microsoft_Windows_Themes:ButtonChrome&gt; &lt;/ControlTemplate&gt; &lt;/Button.Template&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; &lt;/Grid&gt; &lt;/Window&gt; </code></pre> <p><strong>Important note</strong>: The control template is necessary only for the Aero theme. For other themes, just having the Button.Style alone will do the job.</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