Save time creating your application palette
17 Oct 2014 by Nigel SampsonA 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.
- Create all your colour resources
- Copy and paste them below the originals and select the copies
- Open Visual Studio’s Replace in Files (Ctrl + Shift + F for me)
- Under Find options select Use Regular Expressions
- Set Look in: to Selection
- Set Find what to
<Color x:Key="(?<name>\w+)Color">#\w+</Color>
- Set Replace with to
<SolidColorBrush x:Key="${name}Brush" Color="{StaticResource ${name}Color}"/>
- 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.