Save time creating your application palette

A few months ago I wrote a post on building a colour palette for your app, one thing I recommended is creating both the colour and brush resources for each colour separately, like so:

<Color x:Key="PlaceholderColor">#FFEBEBEB</Color>
<SolidColorBrush x:Key="PlaceholderBrush" Color="{StaticResource PlaceholderColor}" />

Large apps can contain a lot of colours once you start including all the shades and tints of your primary colours and creating all these resources can a bit of a tiresome task.

Thankfully we can make use of regular expressions (gasp!) to save some time in Visual Studio.

  1. Create all your colour resources
  2. Copy and paste them below the originals and select the copies
  3. Open Visual Studio’s Replace in Files (Ctrl + Shift + F for me)
  4. Under Find options select Use Regular Expressions
  5. Set Look in: to Selection
  6. Set Find what to <Color x:Key="(?<name>\w+)Color">#\w+</Color>
  7. Set Replace with to <SolidColorBrush x:Key="${name}Brush" Color="{StaticResource ${name}Color}"/>
  8. Hit Replace All

Hopefully this can save you a bit of time building your app or at least teach you what you can do with Visual Studio to save yourself some time.