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,
If you want to inherit the default system colours/styles for a Button
you can use TemplateBinding
s within the button Template
. For example, if you wanted to create a custom-shaped button that had the same background colour as the system one, you could use the below:
<Button>
<Button.Template>
<ControlTemplate TargetType="Button">
<Grid>
<!-- circle to have inherited colour -->
<Ellipse Fill="{TemplateBinding Background}" Height="50" Width="50" />
<ContentPresenter />
</Grid>
</ControlTemplate>
</Button.Template>
</Button>
The Ellipse
will then inherit the background colour from the Button
, however it is set.
You should be able to subclass the normal button control. You can then customize the subclassed button with a custom shape, but all other properties would be inherited. This would allow you to change the shape for your button and nothing else.
Here's a good resource for creating a custom button if you have Blend:
http://msdn.microsoft.com/en-us/library/bb613598.aspx
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>