Reputation: 1697
I am developing a WPF application at my company.
I want to create a RadioButton template.
I want templated RadioButtons to look like standard Buttons.
I want a checked templated RadioButton to look like a pressed standard Button.
The following screenshot part shows a line of 3 RadioButtons and the line below contains 3 Buttons.
I want my template to make the 3 RadioButtons look like the 3 Buttons.
I have read some information about template creation but I do not know how to reference parts of the Button standard template.
I do not want to recreate parts of the Button standard template by drawing 2D shapes.
How can I reference parts of the Button standard template in my RadioButton template ?
Any help will be greatly appreciated
Upvotes: 0
Views: 364
Reputation: 81253
You need to provide Template
of Button
to RadioButton
and you are good to go.
<StackPanel Orientation="Horizontal">
<StackPanel.Resources>
<Style TargetType="RadioButton">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="RadioButton">
<Border BorderThickness="{TemplateBinding Border.BorderThickness}"
BorderBrush="{TemplateBinding Border.BorderBrush}"
Background="{TemplateBinding Panel.Background}"
Name="border"
SnapsToDevicePixels="True">
<ContentPresenter RecognizesAccessKey="True"
Content="{TemplateBinding ContentControl.Content}"
ContentTemplate="{TemplateBinding
ContentControl.ContentTemplate}"
ContentStringFormat="{TemplateBinding
ContentControl.ContentStringFormat}"
Name="contentPresenter"
Margin="{TemplateBinding Control.Padding}"
HorizontalAlignment="{TemplateBinding
Control.HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding
Control.VerticalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding
UIElement.SnapsToDevicePixels}"
Focusable="False" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</StackPanel.Resources>
<RadioButton Content="First"/>
<RadioButton Content="Second"/>
<RadioButton Content="Third"/>
</StackPanel>
Create the default style under your StackPanel resources so that it gets applied automatically to all radioButtons.
Upvotes: 1