Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I like the look of this challenge!</p> <p>Q1: The other comments / answers are correct, templates cannot be modified or inherited. However, there are ways of passing values into your template in order to modify their appearance. A simple (yet slightly hacky way) would be to pass the border <code>CornerRadius</code> into the template using the Tag <code>enter code here</code>property. A better way might be to subclass button to add a 'location' property.</p> <p>Q2: Yes, you are on the right track with styles / templates</p> <p>Q3: Modify your template to include an <code>OpacityMask</code> that has the gradient you desire. You can then either place an element behind this mask or have the masked element take the background colour itself. Complete example shown below:</p> <p><img src="https://i.stack.imgur.com/i7Rd5.png" alt="enter image description here"></p> <pre><code>&lt;Window x:Class="WpfApplication1.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;Window.Resources&gt; &lt;Style x:Key="GoogleButton" TargetType="{x:Type Button}"&gt; &lt;Setter Property="Background" Value="White"/&gt; &lt;Setter Property="Foreground" Value="#666666"/&gt; &lt;Setter Property="Tag"&gt; &lt;Setter.Value&gt; &lt;CornerRadius&gt;0&lt;/CornerRadius&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;Setter Property="FontFamily" Value="Arial"/&gt; &lt;Setter Property="FontSize" Value="13"/&gt; &lt;Setter Property="FontWeight" Value="Bold"/&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="Button"&gt; &lt;Border Name="dropShadowBorder" BorderThickness="0,0,0,1" CornerRadius="1" BorderBrush="Transparent" Background="White"&gt; &lt;Grid&gt; &lt;Border Name="backgroundFill" BorderBrush="Red" Background="{TemplateBinding Background}" CornerRadius="{TemplateBinding Tag}"&gt; &lt;Border.OpacityMask&gt; &lt;LinearGradientBrush StartPoint="0,1" EndPoint="0,0"&gt; &lt;GradientStop Color="#FF000000" Offset="0"/&gt; &lt;GradientStop Color="#00000000" Offset="1"/&gt; &lt;/LinearGradientBrush&gt; &lt;/Border.OpacityMask&gt; &lt;/Border&gt; &lt;Border Name="border" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}" CornerRadius="{TemplateBinding Tag}" Background="Transparent"&gt; &lt;Border.BorderBrush&gt; &lt;SolidColorBrush Color="#D8D8D8"/&gt; &lt;/Border.BorderBrush&gt; &lt;ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/&gt; &lt;/Border&gt; &lt;/Grid&gt; &lt;/Border&gt; &lt;ControlTemplate.Triggers&gt; &lt;Trigger Property="IsMouseOver" Value="True"&gt; &lt;Setter Property="BorderBrush" TargetName="border"&gt; &lt;Setter.Value&gt; &lt;SolidColorBrush Color="#939393"/&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;Setter Property="BorderBrush" TargetName="dropShadowBorder"&gt; &lt;Setter.Value&gt; &lt;SolidColorBrush Color="#EBEBEB"/&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Trigger&gt; &lt;/ControlTemplate.Triggers&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;Style.Triggers&gt; &lt;Trigger Property="IsMouseOver" Value="True"&gt; &lt;Setter Property="Foreground" Value="#333333"/&gt; &lt;/Trigger&gt; &lt;Trigger Property="IsPressed" Value="True"&gt; &lt;Setter Property="Background"&gt; &lt;Setter.Value&gt; &lt;LinearGradientBrush StartPoint="0,1" EndPoint="0,0"&gt; &lt;GradientStop Color="#F1F1F1" Offset="1"/&gt; &lt;GradientStop Color="#F5F5F5" Offset="0"/&gt; &lt;/LinearGradientBrush&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Trigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;/Window.Resources&gt; &lt;Grid&gt; &lt;StackPanel Orientation="Horizontal" VerticalAlignment="Top"&gt; &lt;Button Style="{StaticResource GoogleButton}" Content="Archive"&gt; &lt;Button.Tag&gt; &lt;CornerRadius&gt;2,0,0,2&lt;/CornerRadius&gt; &lt;/Button.Tag&gt; &lt;/Button&gt; &lt;Button Style="{StaticResource GoogleButton}" Content="Spam" Background="LightBlue"/&gt; &lt;Button Style="{StaticResource GoogleButton}" Content="Delete"&gt; &lt;Button.Tag&gt; &lt;CornerRadius&gt;0,2,2,0&lt;/CornerRadius&gt; &lt;/Button.Tag&gt; &lt;/Button&gt; &lt;/StackPanel&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre>
 

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