I would like to change the shape of a WPF button from the default round rectangle to another shape (say, an arrow), but I want to keep the rest of the styling -- fill color, border color, hover states, etc. I want the button to have the same styles as all the other regular buttons (which I believe depends on the version of Windows, system theme colors, etc. so it's not like I can recreate the button style from scratch and hard code the right colors).
Is there some way to do that?
The button's shape can be changed to any shape by applying the control template to a button.
You can achieve rounded corners on a button without having to write any XAML (other than a Style, once) and without having to replace the template or set/change any other properties. Just use an EventSetter in your style for the button's "Loaded" event and change it in code-behind.
Toggle Button is known as a control with the help of which we can move from one state to another state. CheckBox and RadioButton are an example of the Toggle Button.
Make a copy of the default Button Template, and simply change the default panel to your own custom shape.
In the case of the button, it looks like you need to replace the Border
with something like a Path
defining an Arrow.
Since a Path
doesn't have content, you'll probably have to put both the shape and the content in another panel which allows objects to overlap, such as a Grid.
So your end result will look something like this
<Grid>
<Path />
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
instead of the default
<Button>
<ContentPresenter />
</Button>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With