I created a custom ToggleButton class, ToggleButtonEx, that extends ToggleButton. ToggleButtonEx contains some dependency properties that I created in order to use them in a template. I want to base the style of all of my radio buttons on the new toggle button style. Here is what I have:
The ToggeButtonEx style, which defines the template:
<Style TargetType="{x:Type local:ToggleButtonEx}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:ToggleButtonEx}">
...
The radio button style, based off of the ToggleButtonEx style:
<Style BasedOn="{StaticResource {x:Type local:ToggleButtonEx}}" TargetType="{x:Type RadioButton}">
This does not work though. According to msdn,
"If you create a style with a TargetType property and base it on another style that also defines a TargetType property, the target type of the derived style must be the same as or be derived from the type of the base style."
Since radio button is derived from ToggleButton and not ToggleButtonEx, I can't apply the style an I need the toggle button style to be based off of ToggleButtonEx or else I can't use my custom dependency properties in the template. Is there a way to do this?
UPDATE:
Here is my requirement. Maybe someone can help with an alternate solution.
I want to display radio buttons as toggle buttons, so that they look like toggle buttons but maintain the radio button mutually exclusive functionality. This was not hard to do. I created a style targeting ToggleButton to set up my desired toggle button style and then created a new style targeting RadioButton which was based off of the toggle button style.
Now in my ToggleButton style, I change the ControlTemplate to make the button have rounded corners. I decided that I would like different buttons to have different CornerRadius', or no rounding at all. I asked how that can be done in this post:
Inheriting/overriding WPF styles
One suggestion was to create a custom ToggleButton and add a new property so that it can be used in a TemplateBinding. I tried that but it looks like if it is possible, I am not doing it right. I would like to avoid adding a new style each time I need a different value of CornerRadius.