I wanted to group a number of toggle buttons and have them behave as radio buttons. So what I did was add radio buttons to my xaml and created the following style:
<Style BasedOn="{StaticResource {x:Type ToggleButton}}" TargetType="RadioButton">
<Setter Property="FontFamily" Value="Arial"/>
<Setter Property="FontSize" Value="12"/>
<Setter Property="Foreground" Value="White"/>
<Style.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Background" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
Now the radio buttons look like toggle buttons, and the font and foreground properties of the style are applied, but if I click on one of the toggle buttons, the background is not changed to red. If I change the foreground based on IsChecked, it works, but I can't get the Background to change when IsChecked is true.
Any ideas?
UPDATE:
It seems that the default ToggleButton style does not use the Background property. I am using the below code now to solve my problem. If anyone sees anything wrong with the below, please let me know.
<DataTemplate x:Key="RedBackground">
<Grid Background="Red">
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" TextAlignment="Center" Text="{Binding}"/>
</Grid>
</DataTemplate>
<Style TargetType="ToggleButton">
<Style.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
<Setter Property="ContentTemplate" Value="{StaticResource RedBackground}"/>
</Trigger>
</Style.Triggers>
</Style>