Adding a parameter to a WPF control style

In this post I will demonstrate how to add a new parameter to a WPF control style without overriding the control parent class.

In particular I have created a custom button style that relies on the CornerRadius parameter to round any of the four corners of the button. Using this button style I have created a sample keypad shown below:

Keypad

In order to add a CornerRadius parameter I had to add a simple class to the project.

To use the CornerRadius extension in a Window or UserControl class I added the StyleExttension class namespace (in this case WpfStyleParam) to the xaml:

In the Window.Resources I declared KeypadButtonStyle binding corner radius to the Border control in the Button template.

To create a button with a top left rounded corner set the KeypadButtonStyle style and CornerRadius in a Button control:

Download Code