Using HSL colors in WPF
One thing that has always irritated me about WPF is you’re still stuck specifying colors in RGB. HSL just feels so much more natural from a design standpoint. Well, we’re not completely out of luck—we’ve got markup extensions.
So I created my own HslColor and HslBrush extensions which are fairly simple to use:
<Window xmlns:e="clr-namespace:WpfExtensions" Background="{e:HslBrush H=300,S=50,L=75,A=80}"/>
Hue is specified in degrees from 0 to 360, while Saturation, Lightness, and Alpha are from 0 to 100. The parameters are all doubles and it converts to scRGB behind the scenes, which means you actually get a much higher color precision than if you had just used the equivalent RGB hex. With Windows 7 having native support for scRGB, this will future-proof your application to make good use of upcoming monitors with Deep Color support.
Related Posts
- Alex Filo has the right idea, UniformWrapPanel on March 06, 2009 in .NET Framework, C#, Coding, WPF, XAML
- Converting SVG to XAML on June 01, 2008 in .NET Framework, Coding, WPF, XAML
- Visual Studio 2010 CTP now available on October 28, 2008 in C#, Coding
- Databinding TextBlocks with XAML on March 02, 2009 in .NET Framework, C#, Coding, WPF, XAML
- C#: lamer by the moment on November 04, 2008 in .NET Framework, C#, Coding