XAML create button template [duplicate] - wpf

This question already has answers here:
WPF C# button style
(5 answers)
Closed 5 years ago.
I have created a custom looking button in XAML, which is defined as below:
<Button Margin="10,30,10,10" Height="100" Grid.Column="1" Command="{Binding HelpCommand}">
<Button.Template>
<ControlTemplate>
<Border x:Name="Overlay" CornerRadius="15" Background="#4F81BD">
<TextBlock Foreground="Black"
Text="Help"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="26"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter TargetName="Overlay" Property="Background" Value="#FF008DCF"/>
<Setter TargetName="Overlay" Property="BorderBrush" Value="#FF1BB7FF"/>
<Setter TargetName="Overlay" Property="BorderThickness" Value="2"/>
</Trigger>
<Trigger Property="IsEnabled" Value="true">
<Setter TargetName="Overlay" Property="BorderBrush" Value="Black"/>
<Setter TargetName="Overlay" Property="BorderThickness" Value="2"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="Overlay" Property="BorderThickness" Value="3"/>
<Setter TargetName="Overlay" Property="Background" Value="#FF44C3FF"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
How I would like to save this template with a name, and every time I need a button like this, just use the Style property like this:
Style="{StaticResource BackButtonStyle}"
How can I do this?

First you would have to declare your style in a dictionary file
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="CompIconButton" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<!--Anything-->
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
Then you need to declare this dictionary in your application's resources
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Generic_UI/Buttons_Resources.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
And you will finally be able to use your button style as expected
<Button Click="Button_Click" Style="{StaticResource CompIconButton}"/>

You have to style it and save it in a separate .xaml file then load it either for complete app or for each control/window that wants to use it.
This is an example I made you can change it and use it.
<Style x:Key="DefBtn" TargetType="{x:Type Button}">
<Setter Property="Background" Value="#EBEBEB"/>
<Setter Property="BorderBrush" Value="#8C8C8C"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Foreground" Value="Black"/>
<Setter Property="FontSize" Value="12"/>
<Setter Property="FontFamily" Value="Segoe UI regular"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="Padding" Value="3,2"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Name="border"
BorderThickness="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}"
BorderBrush="{TemplateBinding BorderBrush}"
CornerRadius="1"
Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Now you can change the name and add it as a resource dictionary to your project.
And when you want to load it you can do like this.
<Window.Resources>
<ResourceDictionary Source="pack://application:,,,/SomeName;component/NameOfYourXamlFile.xaml"/>
</Window.Resources>

Assing the ControlTemplate an x:Key and move it to your App.xaml file:
<Application x:Class="WpfApplication1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ControlTemplate x:Key="MyButtonTemplate">
<Border x:Name="Overlay" CornerRadius="15" Background="#4F81BD">
<TextBlock Foreground="Black"
Text="Help"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="26"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter TargetName="Overlay" Property="Background" Value="#FF008DCF"/>
<Setter TargetName="Overlay" Property="BorderBrush" Value="#FF1BB7FF"/>
<Setter TargetName="Overlay" Property="BorderThickness" Value="2"/>
</Trigger>
<Trigger Property="IsEnabled" Value="true">
<Setter TargetName="Overlay" Property="BorderBrush" Value="Black"/>
<Setter TargetName="Overlay" Property="BorderThickness" Value="2"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="Overlay" Property="BorderThickness" Value="3"/>
<Setter TargetName="Overlay" Property="Background" Value="#FF44C3FF"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</ResourceDictionary>
</Application.Resources>
</Application>
You can then reference it throughout your whole application using the x:Key:
<Button Template="{StaticResource MyButtonTemplate}" Margin="10,30,10,10" Height="100" Grid.Column="1" Command="{Binding HelpCommand}">
You can do the same thing for a Style (instead of a ControlTemplate).

Related

Reference object inside XAML template

I have resource dictionary for my radio button which adds textbox to it. I want to add trigger which adds left margin to this textbox but I don't know how to reference it
I marked place where I want to add reference
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style BasedOn="{StaticResource {x:Type ToggleButton}}"
TargetType="{x:Type RadioButton}"
x:Key="MenuButtonTheme">
<Style.Setters>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="RadioButton">
<Grid VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Background="{TemplateBinding Background}">
<TextBlock Text="{TemplateBinding Property=Content}"
VerticalAlignment="Center"
Margin="20,0,0,0">
</TextBlock>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Background" Value="Transparent"></Setter>
<Setter Property="BorderThickness" Value="0"></Setter>
</Style.Setters>
<Style.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Margin" Value="30,0,0,0"></Setter> <!-- Reference TextBlock here -->
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#424549"></Setter>
</Trigger>
</Style.Triggers>
</Style>
</ResourceDictionary>
You need to set triggers not in Style, but in ControlTemplate. Then you can refer to template elements by name:
<ControlTemplate TargetType="RadioButton">
<Grid x:Name="PART_Main" VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Background="{TemplateBinding Background}">
<TextBlock x:Name="PART_TBlock"
Text="{TemplateBinding Property=Content}"
VerticalAlignment="Center"
Margin="20,0,0,0"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter TargetName="PART_TBlock" Property="Margin" Value="30,0,0,0"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="PART_Main" Property="Background" Value="#424549"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>

WPF application: Tool tip not started all across all my application

I have WPF application and I am using materialDesign.
This is my app.xaml:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.ToolTip.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
My style:
<Style TargetType="{x:Type ToolTip}">
<Setter Property="OverridesDefaultStyle" Value="False"/>
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Foreground" Value="Silver"/>
<Setter Property="FontSize" Value="11"/>
<Setter Property="Placement" Value="Bottom"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="ToolTipService.ShowDuration" Value="10000"/>
<Setter Property="ToolTipService.HorizontalOffset" Value="-20"/>
<Setter Property="ToolTipService.Placement" Value="Left"/>
<Setter Property="ToolTipService.ShowsToolTipOnKeyboardFocus" Value="True"/>
<Setter Property="Margin" Value="0,0,0,0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToolTip}">
<Border x:Name="Root" CornerRadius="5" BorderThickness="1" BorderBrush="{DynamicResource SettingsLeftMenueBackgroundColor}" Background="{DynamicResource ToolTipBackgroundColor}">
<ContentPresenter Margin="10" HorizontalAlignment="Left" VerticalAlignment="Top"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsOpen" Value="False">
<Setter TargetName="Root" Property="Visibility" Value="Collapsed"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Some control:
<Button Name="btnSettings"
Padding="0"
Cursor="Hand"
Command="{Binding OpenSettingsFormCommand}">
<Button.ToolTip>
<ToolTip Content="Settings"
ToolTipService.Placement="Top"/>
</Button.ToolTip>
</Button>
And I cannot see this ToolTip at all.
I try to remove MaterialDesignTheme.ToolTip.xaml from my app.xaml or add key into my ToolTip style and using this style via key but this not helped at all.
My ToolTip missing across all my application.

IntegerUpDown Style Up/down buttons

I am trying to style a integerupdown(Xceed framework) control and my wpf knowledge in lacking. So far I have gotten it styled for everything but the OnMouseOver which still looks like a "normal" button mouseover.
How can I set the style on mouseover? Remove the blue automatic background.
<UserControl.Resources>
<Style x:Key="{x:Static theme:ResourceKeys.SpinnerButtonStyleKey}" TargetType="RepeatButton">
<Setter Property="Foreground" Value="#fff" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Background" Value="#555555"></Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Red"></Setter>
<Setter Property="Background" Value="Black"></Setter>
</Trigger>
</Style.Triggers>
</Style>
<Style TargetType="{x:Type xctk:IntegerUpDown}">
<Style.Resources>
<SolidColorBrush x:Key="{x:Static theme:ResourceKeys.GlyphNormalForegroundKey}" Color="#e9e9ee"/>
</Style.Resources>
</Style>
</UserControl.Resources>
You should define a custom RepeatButton style for the themes:ResourceKeys.SpinnerButtonStyleKey resource:
<xctk:IntegerUpDown
xmlns:themes="clr-namespace:Xceed.Wpf.Toolkit.Themes;assembly=Xceed.Wpf.Toolkit"
xmlns:chrome="clr-namespace:Xceed.Wpf.Toolkit.Chromes;assembly=Xceed.Wpf.Toolkit">
<xctk:IntegerUpDown.Resources>
<Style x:Key="{x:Static themes:ResourceKeys.SpinnerButtonStyleKey}"
TargetType="RepeatButton">
<Setter Property="Background" Value="{DynamicResource {x:Static themes:ResourceKeys.ButtonNormalBackgroundKey}}" />
<Setter Property="BorderBrush" Value="{DynamicResource {x:Static themes:ResourceKeys.ButtonNormalOuterBorderKey}}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Padding" Value="2,2" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="RepeatButton">
<Grid>
<chrome:ButtonChrome x:Name="Chrome"
BorderBrush="{TemplateBinding BorderBrush}"
Background="{TemplateBinding Background}"
CornerRadius="{DynamicResource {x:Static themes:ResourceKeys.SpinButtonCornerRadiusKey}}"
RenderEnabled="{TemplateBinding IsEnabled}"
RenderMouseOver="False"
RenderNormal="True"
RenderPressed="{TemplateBinding IsPressed}"
SnapsToDevicePixels="true" />
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Margin="{TemplateBinding Padding}" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Red" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</xctk:IntegerUpDown.Resources>
</xctk:IntegerUpDown>

WPF Style BasedOn does not work

I have made a style RadioButtonToggleButtonStyle as below.
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
d1p1:Ignorable="d"
xmlns:d1p1="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:TeachpendantControl">
<Style x:Key="RadioButtonToggleButtonStyle"
BasedOn="{StaticResource {x:Type ToggleButton}}"
TargetType="{x:Type RadioButton}">
<Style.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Background" Value="Gold"/>
</Trigger>
</Style.Triggers>
</Style>
</ResourceDictionary>
I use it like this below.
<ListBox Grid.Column="0" Grid.Row="0" Grid.RowSpan="10" ItemsSource="{Binding LeftPaneViewModelInfoItems, UpdateSourceTrigger=PropertyChanged}" Background="Transparent" SelectedItem="{Binding SelectedViewModelInfoItem}">
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Background" Value="Transparent" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<ContentPresenter />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<RadioButton
Content="{Binding Text}"
GroupName="DisplayPage"
IsChecked="{Binding IsSelected, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}}}"
Style="{StaticResource RadioButtonToggleButtonStyle}"
>
</RadioButton>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
The CheckBoxes show up as ToggleButtons when I run the application (but it shows up as CheckBoxes in Design mode).
But I don't get a gold background when the CheckBox (styled as ToggleButton) is checked. Also Visual Studio (2015) complains in the resource file saying "The resource {x:Type ToggleButton}" could not be resolved.
Can anyone provide an explanation of why this does not work (and how to solve it)
You need to modify the ControlTemplate to be able to change the Background of a ToggleButton.
The default ControlTemplate contains hardcoded values that take precedence over the value that you specify in your Style.
You can copy the default template into your project by right-clicking on a ToggleButton in design mode in Visual Studio or in Blend and choose Edit Template->Edit a Copy and then edit it as per your requirements. Try this:
<Style x:Key="RadioButtonToggleButtonStyle" TargetType="{x:Type ToggleButton}">
<Style.Resources>
<Style x:Key="FocusVisual">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Rectangle Margin="2" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<SolidColorBrush x:Key="Button.Static.Background" Color="#FFDDDDDD"/>
<SolidColorBrush x:Key="Button.Static.Border" Color="#FF707070"/>
<SolidColorBrush x:Key="Button.MouseOver.Background" Color="#FFBEE6FD"/>
<SolidColorBrush x:Key="Button.MouseOver.Border" Color="#FF3C7FB1"/>
<SolidColorBrush x:Key="Button.Pressed.Background" Color="#FFC4E5F6"/>
<SolidColorBrush x:Key="Button.Pressed.Border" Color="#FF2C628B"/>
<SolidColorBrush x:Key="Button.Disabled.Background" Color="#FFF4F4F4"/>
<SolidColorBrush x:Key="Button.Disabled.Border" Color="#FFADB2B5"/>
<SolidColorBrush x:Key="Button.Disabled.Foreground" Color="#FF838383"/>
</Style.Resources>
<Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/>
<Setter Property="Background" Value="{StaticResource Button.Static.Background}"/>
<Setter Property="BorderBrush" Value="{StaticResource Button.Static.Border}"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Padding" Value="1"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="true">
<ContentPresenter x:Name="contentPresenter" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="Button.IsDefaulted" Value="true">
<Setter Property="BorderBrush" TargetName="border" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Background" TargetName="border" Value="{StaticResource Button.MouseOver.Background}"/>
<Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.MouseOver.Border}"/>
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter Property="Background" TargetName="border" Value="{StaticResource Button.Pressed.Background}"/>
<Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.Pressed.Border}"/>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Background" TargetName="border" Value="{StaticResource Button.Disabled.Background}"/>
<Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.Disabled.Border}"/>
<Setter Property="TextElement.Foreground" TargetName="contentPresenter" Value="{StaticResource Button.Disabled.Foreground}"/>
</Trigger>
<Trigger Property="IsChecked" Value="true">
<Setter Property="Background" TargetName="border" Value="Gold" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

ToggleButton doesn't show any state

I've got the most simple application ever: single window with one single toggle button:
<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">
<Grid>
<ToggleButton Content="This is my ToggleButton" />
</Grid>
</Window>
When I now click on the toggle button, really nothing happens. When I setup event handler for Checked and Unchecked event, and then click the button, first the Checked and then Unchecked get fired. So the button seems to work correctly ...
I am compiling to .NET 4.5 and I am using Windows 8 RTM.
Is this behaviour related to the Windows 8 style of displaying buttons (no "3D" border)? Can anyone confirm?
UPDATE 1
I made up an image to show what I meant:
As you see, in Windows 8 "nothing happens" when clicking on the toggle button, it simply does not get "toggled".
This seems to be a bug, related to the windows 8 style of displaying buttons ...
UPDATE: May 30 2013:
A hotfix is avalible: http://support.microsoft.com/kb/2805222
See Issue #5 under WPF
Unfortunately it doesn't fix the problem for me :(
This is a confirmed defect in WPF. The workaround is to style the control accordingly, although a fix may be considered by the product group. To request a fix, please contact Microsoft Support.
For everybody who want some code to start off with, you can take the code I used to style my controls:
<Application.Resources>
<!-- Toogle button fix (includes custom button + toggle button style) -->
<Style TargetType="{x:Type Button}">
<Setter Property="Background" Value="{StaticResource ButtonNormalBackground}"/>
<Setter Property="BorderBrush" Value="{StaticResource ButtonNormalBorder}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Padding" Value="1"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border BorderThickness="1" BorderBrush="#FFA4A4A4">
<Grid>
<Rectangle x:Name="Rectangle_Background" Fill="#FFEDEDED" />
<ContentPresenter x:Name="ContentPresenter_Content" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter TargetName="Rectangle_Background" Property="Fill" Value="#f7f7f7"/>
<Setter TargetName="ContentPresenter_Content" Property="Opacity" Value="0.5"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Rectangle_Background" Property="Fill" Value="#e0e0e0" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type ToggleButton}">
<Setter Property="Background" Value="{StaticResource ButtonNormalBackground}"/>
<Setter Property="BorderBrush" Value="{StaticResource ButtonNormalBorder}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Padding" Value="1"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Border BorderThickness="1" BorderBrush="#FFA4A4A4">
<Grid>
<Rectangle x:Name="Rectangle_Background" Fill="#FFEDEDED" />
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter TargetName="Rectangle_Background" Property="Fill" Value="#ADADAD"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Rectangle_Background" Property="Fill" Value="#e0e0e0" />
</Trigger>
<Trigger Property="IsChecked" Value="true">
<Setter Property="Fill" TargetName="Rectangle_Background" Value="#bee6fd"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Application.Resources>

Resources