I'm just getting started with my first "serious" WPF application. I've ran into an issue where my Style.Triggers > IsChecked for a RadioButton is not picking up on the changes. When I start my application everything seems fine. When I change pages it should be updating the background color of the buttons. It applies the change as it should when the button IsChecked = True but it never reverts back to the default(Transparent) once it's marked as False.
Items Control:
<ItemsControl ItemsSource="{Binding MainMenuButtons}" Grid.Row="1" Margin="0 0 3 0">
<ItemsControl.ItemTemplate>
<DataTemplate>
<RadioButton Content="{Binding Content}" IsChecked="{Binding IsChecked}"
Command="{Binding Command}" Style="{StaticResource MenuButtonTheme}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
StaticResource MenuButtonTheme:
<Style BasedOn="{StaticResource {x:Type ToggleButton}}" TargetType="{x:Type RadioButton}" x:Key="MenuButtonTheme">
<Style.Setters>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="RadioButton">
<Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Background="{TemplateBinding Background}">
<TextBlock Text="{TemplateBinding Property=Content}" VerticalAlignment="Center" Margin="25,0,0,0"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Foreground" Value="Black" />
<Setter Property="FontSize" Value="14" />
<Setter Property="Height" Value="50" />
</Style.Setters>
<Style.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Background" Value="#5F5F5F" />
</Trigger>
</Style.Triggers>
</Style>
In my view model for now I just say anytime you click on a button set the IsChecked to false for all buttons for testing. This is where it starts to break down. It's like when I update the IsChecked from within the ViewModel everything is fine but the style update doesnt get triggered.
ViewModel Code Chunks:
When you click on a button:
foreach (var button in _mainMenuButtons)
{
button.IsChecked = false;
}
On Startup:
_mainMenuButtons.Add(new MenuButton() { Name = "HomeViewBtn", IsChecked = true, Command = GoToViewHome, Content = "Home"});
_mainMenuButtons.Add(new MenuButton() { Name = "CheckPreviousBatchViewBtn", IsChecked = false, Command = GoToViewCheckPreviousBatch, Content = "Check Previous Batch"});
I have verified that the IsChecked property is indeed set to false in the foreach loop correctly:
Here is what the default startup view looks like(correct):
Here is what it looks like after I click on the view batch button:
If I were to click on Home again it then keeps them all highlighted as if IsChecked is true. Any thoughts or suggestions?