2

I would like to know if there is a setting for WPF in VS2019 to enable "colour preview" in code, such that when I type the hex colour code it displays the colour (without having to apply the colour to any UI element – just a pure visual preview)?

I have a project, where I use a multitude of colours, and it is getting difficult to keep track of which colour is which, so it would be nice to have a visual guide.

My general code for colours in the Resource Dictionary is:

<Color x:Key="BackgroundLight">#efefef</Color> 
<SolidColorBrush x:Key="BackgroundLightBrush" Color="{StaticResource BackgroundLight}" />

Is there such setting in VS2019? I believe I saw something like this in one youtube video, where the hex code was underlined by the corresponding colour, but I can neither figure out how to achieve that, nor can I find the video now.

Tomáš Buchta
  • 366
  • 3
  • 8
  • "I believe I saw something like this in one youtube video" - ReShaper can identify color names and rgb codes, and underline them in editor view. I admit, I took this feature for granted, and though VS has it out-of-box – ASh Nov 20 '19 at 12:09

3 Answers3

1

The newest version of VisualStudio implements this by default now. There is a coloured square next to the colour’s name. Nice.

Tomáš Buchta
  • 366
  • 3
  • 8
0

You can sometimes persuade the colour picker to appear in the properties window.

It is fiddly though and I must admit I can't recall trying with vs2019. EDIT: Having just tried this, I couldn't get it to work with just a color. A control like say the background on a grid with the hex in it works ok but the colorpicker doesn't respond at all when I select a color resource.

There's a vsix

https://marketplace.visualstudio.com/items?itemName=NikolaMSFT.InlineColorPicker

Like you're doing, I usually define colours in a resource dictionary so they have meaningful names.

Once I've done that, the actual colour matters a lot less.

Andy
  • 11,864
  • 2
  • 17
  • 20
  • Thank you for the suggestion, I will try to persuade ColorPicker to cooperate with me. I don't want the colour names to be tens of characters long each. I asked the question because I found the system inconvenient when working with dozens of colours to the point where really precise variable names would result in an added layer of confusion / slowdown. – Tomáš Buchta Nov 20 '19 at 12:29
  • I tried it in vs2019. I think you need a control with the color set on it directly to get the color picker to work. – Andy Nov 20 '19 at 12:53
0

There's a vsix

https://marketplace.visualstudio.com/items?itemName=NikolaMSFT.InlineColorPicker

This extension can't be installed in VisualStudio 2019 Pro, but you can use this method mentioned in another answer as workaround to install it in VisualStudio 2019 Pro.

https://stackoverflow.com/a/62040646/7387963

Mabito
  • 31
  • 3