views:

46

answers:

1

Hi all. I'm trying to make my application force a theme - this is straightforward as shown here: http://arbel.net/blog/archive/2006/11/03/Forcing-WPF-to-use-a-specific-Windows-theme.aspx

However, I don't know what theme I'm using now. I'm using the Windows XP default theme, whatever that may be. That article says

It's important to specify the version and the public key token

...where do I get that information?

+2  A: 

To get the theme name you can call the unmanaged GetCurrentThemeName method:

public string GetThemeName()
{
  StringBuilder themeNameBuffer = new StringBuilder(260);
  var error = GetCurrentThemeName(themeNameBuffer, themeNameBuffer.Capacity, null, 0, null, 0);
  if(error!=0) Marshal.ThrowExceptionForHR(error);
  return themeNameBuffer.ToString();
}

[DllImport("uxtheme.dll", CharSet=CharSet.Auto)]
public static extern int GetCurrentThemeName(StringBuilder pszThemeFileName, int dwMaxNameChars, StringBuilder pszColorBuff, int dwMaxColorChars, StringBuilder pszSizeBuff, int cchMaxSizeChars);

You can find the version and public key token by right-clicking the theme .dll (such as PresentationFramework.Aero) in the GAC (open c:\Windows\Assembly in Exporer), or you can use code to do it. Just loop through all loaded assemblies using AppDomain.CurrentDomain.LoadedAssemblies and find the one you want:

foreach(Assembly a in AppDomain.CurrentDomain.LoadedAssemblies)
  if(a.Name.StartsWith("PresentationFramework."))
    return a.FullName;

Note that looping through the loaded assemblies will also tell you the current theme name if only one theme has been loaded in the current AppDomain.

Ray Burns