切换按钮背景颜色应在其click / IsChecked事件中更改。 请查看以下代码:
<ToggleButton x:Name="BtnArea" Content="{Binding Area, Source={StaticResource Labels}}" Style="{StaticResource FirstButton}" Click="Toggle_Click" Background="Chocolate" />
private void Toggle_Click(object sender, RoutedEventArgs e)
{
ToggleButton obj = (ToggleButton)sender;
((ToggleButton)sender).Background = new SolidColorBrush(Color.FromArgb(155, 0, 255, 0));
obj.Background = new SolidColorBrush(Color.FromArgb(155, 0, 55, 0));
}