-1

I want to use the systemcolor in my design that is used for the hover state of a button. In my image below, you can see the light blue color that is displayed when the user hovers above the "Find and Replace" button. I want to set this color programmatically, so I am trying to set the color from C#. However, when I try to get the RGB values from SystemColors.Highlight the color is wrong. You can see the color used on the "Projects" button below.

Highlight SystemColor compared to displayed highlight color

byte r = SystemColors.Highlight.R;
byte g = SystemColors.Highlight.G;
byte b = SystemColors.Highlight.B;
Ryan Daley
  • 15
  • 6
  • Why are you getting rgb values in the first place? what about the alpha value (transparency)? does this help? https://stackoverflow.com/questions/9276813/cast-color-name-to-solidcolorbrush – Rand Random Aug 03 '23 at 08:41
  • 1
    You should use the WPF [SystemColors](https://learn.microsoft.com/en-us/dotnet/api/system.windows.systemcolors?view=windowsdesktop-7.0) class and use for example either the `HighlightColor` or the `HighlightBrush` property. Be aware however that the ControlTemplate of the Button does by default not use the Background color for visualizing the "mouse over" state. – Clemens Aug 03 '23 at 09:12
  • @Clemens your right, it looks like it uses the BorderBrush property ``` ``` – Ryan Daley Aug 03 '23 at 11:47
  • @Clemens I still can't figure out how to replicate this behavior from binding to the ViewModel. I'm trying ```BorderBrush="{Binding HighlightColor}"``` However, I don't know what the property type should be. Is it a `Color` or a `SolidColorBrush` ? Then, I don't know how to recreate the Color even with a known hexadecimal. `"#FF3C7FB1"` – Ryan Daley Aug 03 '23 at 11:57
  • As the name implies, BorderBrush is a Brush, not a Color. Bind it to a view model property of type Brush or use a value like SystemColors.HighlightBrush. – Clemens Aug 03 '23 at 12:04

1 Answers1

0
btnUp.Background = new SolidColorBrush(Color.FromRgb(0,0,0));

try this.

  • Answer needs supporting information Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](https://stackoverflow.com/help/how-to-answer). – moken Aug 03 '23 at 09:58