I have the following style for buttons:
<Style TargetType="Button">
<Setter Property="SnapsToDevicePixels" Value="true" />
<Setter Property="FontFamily" Value="Roboto" />
<Setter Property="MinHeight" Value="{StaticResource ButtonMinHeight}" />
<Setter Property="MinWidth" Value="{StaticResource ButtonMinWidth}" />
<Setter Property="Padding" Value="{StaticResource ButtonPadding}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border x:Name="bMain"
CornerRadius="{StaticResource ButtonCornerRadius}"
BorderThickness="{StaticResource ButtonBorderThickness}"
BorderBrush="Transparent"
Background="{StaticResource ButtonBackgroundBrush}"
TextBlock.Foreground="{StaticResource ButtonForegroundBrush}">
<ContentPresenter Margin="{TemplateBinding Padding}"
HorizontalAlignment="Center"
VerticalAlignment="Center"
RecognizesAccessKey="True" />
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="MouseOver">
<Storyboard>
<ColorAnimationUsingKeyFrames Storyboard.TargetName="bMain" Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
<DiscreteColorKeyFrame KeyTime="0" Value="{StaticResource ButtonHoverBackgroundColor}" />
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed">
<Storyboard>
<ColorAnimationUsingKeyFrames Storyboard.TargetName="bMain" Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
<DiscreteColorKeyFrame KeyTime="0" Value="{StaticResource ButtonDownBackgroundColor}" />
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled">
<Storyboard>
<ColorAnimationUsingKeyFrames Storyboard.TargetName="bMain" Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)">
<DiscreteColorKeyFrame KeyTime="0" Value="{StaticResource ButtonDisabledForegroundColor}" />
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsDefault" Value="True">
<Setter TargetName="bMain" Property="BorderBrush" Value="{StaticResource ButtonBorderBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Also, I have two buttons:
<Button Grid.Column="1" Command="{Binding LogCommand}" Content="{x:Static r:Strings.Main_Button_Log}" Margin="0,0,24,0"/>
<Button Grid.Column="2" Command="{Binding CloseCommand}" Content="{x:Static r:Strings.Main_Button_Close}" />
The problem is that they both seem to receive the same state at the same time.
Normal:
Hover (on one of them):
If the images are not distinct enough, in the second one both buttons became highlighted instead of only one. The case is the same for pressing.
How can I fix this?
question from:
https://stackoverflow.com/questions/65886003/why-all-buttons-receive-the-same-state-at-once-in-wpf 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…