Last active
July 25, 2023 06:42
-
-
Save dady8889/8296f6085e11e39e277ae156c075ffa5 to your computer and use it in GitHub Desktop.
C# WPF - Windows 10 Button Style
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Style | |
x:Key="ButtonFocusVisual"> | |
<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> | |
<Style x:Key="Windows10Button" TargetType="{x:Type Button}"> | |
<Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}"/> | |
<Setter Property="Background" Value="#dddddd"/> | |
<Setter Property="Foreground" Value="Black"/> | |
<Setter Property="HorizontalContentAlignment" Value="Center"/> | |
<Setter Property="VerticalContentAlignment" Value="Center"/> | |
<Setter Property="FontSize" Value="12" /> | |
<Setter Property="BorderThickness" Value="1" /> | |
<Setter Property="BorderBrush" Value="#7a7a7a"/> | |
<Setter Property="Height" Value="20" /> | |
<Setter Property="Cursor" Value="Hand" /> | |
<Setter Property="Template"> | |
<Setter.Value> | |
<ControlTemplate TargetType="{x:Type Button}"> | |
<Grid> | |
<Border | |
x:Name="Border" | |
Background="{TemplateBinding Background}" | |
BorderBrush="{TemplateBinding BorderBrush}" | |
BorderThickness="{TemplateBinding BorderThickness}" /> | |
<ContentPresenter | |
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" | |
Margin="{TemplateBinding Padding}" | |
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" | |
RecognizesAccessKey="True" /> | |
</Grid> | |
<ControlTemplate.Triggers> | |
<Trigger Property="IsMouseOver" Value="True"> | |
<Setter Property="Background" Value="#bee6fd" TargetName="Border"/> | |
<Setter Property="BorderBrush" Value="#3c7fb1" TargetName="Border"/> | |
</Trigger> | |
<Trigger Property="IsPressed" Value="True"> | |
<Setter Property="Background" Value="#c4e5f6" TargetName="Border"/> | |
<Setter Property="BorderBrush" Value="#2c628b" TargetName="Border"/> | |
</Trigger> | |
<Trigger Property="IsEnabled" Value="False"> | |
<Setter Property="Background" Value="#f4f4f4" TargetName="Border"/> | |
<Setter Property="BorderBrush" Value="#adb2b5" TargetName="Border"/> | |
<Setter Property="Foreground" Value="#838383"/> | |
</Trigger> | |
</ControlTemplate.Triggers> | |
</ControlTemplate> | |
</Setter.Value> | |
</Setter> | |
</Style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on https://gist.github.com/alimbada/3083937.
Copy the code to your ResourceDictionary (in Generic.xaml for example), and put Style="{StaticResource Windows10Button}" on your buttons.
Comparison between this and Windows 10: http://imgur.com/a/EHMOJ
Made this because I wanted the same look on all Windows versions.