MaterialDesignInXamlToolkit icon indicating copy to clipboard operation
MaterialDesignInXamlToolkit copied to clipboard

MaterialDesignFlatAccentButton Style has incorrect background hover color

Open npuc85 opened this issue 6 years ago • 2 comments

In https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/blob/master/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Button.xaml the definition for MaterialDesignFlatAccentButton is based on MaterialDesignFlatButton but the only change is to the Foreground color to SecondaryHueMidBrush, so it's still using the IsMouseOver Trigger from the base style:

                        <Trigger Property="IsMouseOver" Value="true">
                            <Setter Property="BorderBrush" TargetName="border" Value="{DynamicResource PrimaryHueMidBrush}" />
                            <Setter Property="Background" TargetName="border" Value="{DynamicResource PrimaryHueMidBrush}" />
                        </Trigger>

As you can see, it's setting the background and border brush to PrimaryHueMidBrush but since this is an Accent button style, it should overwrite the base color and instead use SecondaryHueMidBrush.

I can see what's causing the problem, I'm just not sure how to fix it myself, short of copying the entire style and replacing the color in the trigger setter. I'm sure there's a better way to fix it that I just don't know myself.

Incidentally, this button style does not appear anywhere on the Demo app, I suspect if it did this would have been spotted and fixed.

npuc85 avatar Oct 18 '20 06:10 npuc85

IMO a solution would be to do the following:

  • [ ] Create a new attached properties in the ButtonAssist class. Something like like FlatButtonMouseOverBackground and FlatButtonMouseOverOpacity
  • [ ] Default the attached properties in the base style to {DynamicResource PrimaryHueMidBrushColor} and 0.16 respectively.
  • [ ] Remove the hard coded resource PrimaryHueMidBrush from the control template in the base style
  • [ ] Change the template to use a multi binding (with a new converter) that uses the two attached properties to set the brushes inside of the IsMouseOver trigger.
  • [ ] Update the derived styles to set the attached properties to the appropriate theme brush

Bonus point if there are UI tests to go with it.

Keboo avatar Oct 20 '20 03:10 Keboo

@Keboo Instead of attached property we could use a converter like BrushOpacityConverter to applying the primary or secondary brush as IsMouseOver background. I already created a PR (#2131) for similar issue (#2130). Also, I think we don't need change BorderBrush for MaterialDesignFlatButton

https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/blob/d75bac11b6d25ad34c78e416b26727344da8c487/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Button.xaml#L177-L180

AmRo045 avatar Oct 20 '20 05:10 AmRo045