Search code examples
c#wpfxamlaero

Get Aero Window Colour


I've made a pretty slick Windows 8-ish interface using WPF. It already turns out way better than I could wish for, but I was wondering the following:

Is it somehow possible to retrieve the current window colour set by the user? You know, you can set the Aero colour when you right-click the desktop... My plan is to use that colour for a couple of canvas elements on my GUI.

Thanks in advance!


Solution

  • You can query the ColorizationColor registry key for this.

    I've even went a step further and created a method to get the hexadecimal colour value, hope this helps you:

    public void SomeMethod()
    {
        int argbColor = (int)Microsoft.Win32.Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM","ColorizationColor", null);
        var color = System.Drawing.Color.FromArgb(argbColor);
        string hexadecimalColor = ConverterToHex(color);
    }
    
    
    private static String ConverterToHex(System.Drawing.Color c)
    {
        return String.Format("#{0}{1}{2}", c.R.ToString("X2"), c.G.ToString("X2"), c.B.ToString("X2"));
    }