1

I am trying to find an easy way to change the color of an existing SolidColorBrush by adding a transparent overlay color. Is this possible without

  • using shader effects, or
  • putting a duplicate control on top with the overlay color?

I have been told that this MUST be possible on windows. Web developers are using this technique all the time, and this is how they communicate with the designers. They have a couple of key colours for a design, and they don't explicitly define each shade of a key color - instead they say "add 10% black". I know that this can be done easily in CSS, there you don't have to worry about the exact RGB values, all you have to define is just a blending with a 10% transparent black color. I am looking for something similar for WPF, where I could easily modify my existing colors without too much extra hassle (e.g. making a brush 10% darker, as if there was a 10% black object on top of it.)

I am not looking for a mathematical calculation for overlays, I know this can be done. I am looking for a trivial way to achieve this in WPF - similarly to CSS, where you can simply define overlay colors for blending. I would like to know if this is possible or not - in WPF.

Peter Bulyaki
  • 309
  • 5
  • 10
  • Weird looking solution is [here](http://stackoverflow.com/a/4802515/1997232). I'd personally give a job to designer to create a set of colors for me with different alphas... maybe this is why I don't have one yet. – Sinatr Aug 11 '15 at 11:49
  • 'I have been told that this MUST be possible on windows' - if someone told you this, I'd suggest asking them how to do it. It's not something I've come across in WPF before, although I am looking forward to being proven wrong. – goobering Aug 11 '15 at 11:51
  • Are you looking for CMYK colors? If so try this post http://stackoverflow.com/questions/4827270/using-cmyk-colours-in-wpf-xaml – tobyUCT Aug 11 '15 at 11:52
  • Not CMYK, I know in that case it would be easy :). Its ARGB. – Peter Bulyaki Aug 11 '15 at 11:55
  • I have already asked the design team to provide me with exact colors - however I can fully understand their point too. They have never dealt with grumpy windows developers like me in the past, and they got used to saying 20% black, etc. I would like to find an easy solution to this. Right now the only solution I see is that we open Photoshop, put a 10% black layer on top of the colors, and write down how each color changes after flattening down the layer. Either they do this, or I do. – Peter Bulyaki Aug 11 '15 at 11:59
  • There's some potentially interesting reading here: https://social.msdn.microsoft.com/Forums/vstudio/en-US/3e21d503-c893-44f6-9f7f-129fe01c51e2/ivalueconverter-for-color . Lots of RGB -> HLS conversion code and a ValueConverter. I wonder if you could hard code different Converters for different lightness/darkness values and apply those as required? – goobering Aug 11 '15 at 12:04
  • Thanks goobering, this may work fine for blending black with X% transparency - this is almost like reducing the luminosity by 10%. Unfortunately this would not work for "blending with 10% pink". – Peter Bulyaki Aug 11 '15 at 12:17
  • Sinatr, that solution has nothing to do with what I asked, not even close. I was asking for blending two colors. You posted a random color-related answer, that is about defining colors in a ResourceDictionary. – Peter Bulyaki Aug 11 '15 at 12:26
  • How is 'pink' specified? I think (hope I'm wrong) that you're likely to have to change the colors in question, rather than somehow overlaying them. At the end of the day that's going to come down to something like a ValueConverter. If you can define the pink you can create a Converter to apply the necessary alteration, but I think it's likely to be a nigh on infinite, unending PITA. – goobering Aug 11 '15 at 12:27
  • Substitute pink with any color that is not a shade of black/gray. If the overlay color is a shade of black, you can achieve the same effect just by changing L. If it is a different color, then you can't do the same. This is what I would like to find out too. The reason I asked this question is because I doubt I know everything possible about WPF brushes, so I was hoping there is an easier way to calculate an overlay color on the fly, at runtime. If this can't be calculated EASILY at runtime, then the colors have to be predefined. A "not possible" answer is also an answer for me in this case. – Peter Bulyaki Aug 11 '15 at 12:39
  • An "easy way" without using shader effects or control overlay, is to mix ARGB values, as shown in the answer to the question linked as duplicate. – Clemens Aug 11 '15 at 13:28
  • That answer is using a paper and a pencil, and not WPF + SolidColorBrush. I still don not know, if WPF has a builtin feature to achieve this or not. Now that you marked it as a duplicate probably never will. – Peter Bulyaki Aug 11 '15 at 13:34
  • No, WPF does not have the built-in feature you are looking for. You should just accept that. – Clemens Aug 11 '15 at 18:04
  • I am more than happy to accept that. This is what I was asking in the first place. I wanted to know if an obvious, trivial solution exists. The answer you have set as duplicate is **not answering this yes/no question** at all, it provides an alternative solution. I was not asking for an alternative solution, I know how to google "ARGB color blending". – Peter Bulyaki Aug 12 '15 at 11:43

0 Answers0