Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Button FlatStyle in WPF

I have just been learning about how styles and control templates in WPF can affect the appearance of buttons,

I'm trying to set the Button's FlatStyle, in the resources I've seen I can't find anything that tells me how I can do this, in Windows Forms this is set through FlatStyle = Flat.

How would one do this in WPF?

like image 378
MrEdmundo Avatar asked Mar 30 '09 14:03

MrEdmundo


2 Answers

The ToolBar class defines a Style that makes Buttons look flat. An example of using it is:

<Button Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"/>

This also works for a ToggleButton when using ToggleButtonStyleKey.

WPF lets you completely restyle controls to make them look like whatever you want, which is why it doesn't have such a specific FlatStyle property on the Button control.

like image 170
Kent Boogaart Avatar answered Oct 23 '22 15:10

Kent Boogaart


Add the following to your Window/Page resources:

<Style BasedOn="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" TargetType="Button"></Style>

It will apply the flat style to all buttons in that styles scope.

like image 25
PhonicUK Avatar answered Oct 23 '22 13:10

PhonicUK