我正在尝试使我的应用程序成为一个主题 - 这很简单,如下所示:http: //arbel.net/blog/archive/2006/11/03/Forcing-WPF-to-use-a-specific-Windows -theme.aspx
但是,我不知道我现在使用的是什么主题。我使用的是 Windows XP 默认主题,不管它是什么。那篇文章说
指定版本和公钥令牌很重要
...我从哪里得到这些信息?
我正在尝试使我的应用程序成为一个主题 - 这很简单,如下所示:http: //arbel.net/blog/archive/2006/11/03/Forcing-WPF-to-use-a-specific-Windows -theme.aspx
但是,我不知道我现在使用的是什么主题。我使用的是 Windows XP 默认主题,不管它是什么。那篇文章说
指定版本和公钥令牌很重要
...我从哪里得到这些信息?
要获取主题名称,您可以调用非托管 GetCurrentThemeName 方法:
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);
您可以通过右键单击 GAC 中的主题 .dll(例如 PresentationFramework.Aero)找到版本和公钥令牌(在 Exporer 中打开 c:\Windows\Assembly),也可以使用代码来完成。只需使用 AppDomain.CurrentDomain.LoadedAssemblies 遍历所有加载的程序集并找到您想要的程序集:
foreach(Assembly a in AppDomain.CurrentDomain.LoadedAssemblies)
if(a.Name.StartsWith("PresentationFramework."))
return a.FullName;
请注意,如果当前 AppDomain 中仅加载了一个主题,则循环加载的程序集还将告诉您当前的主题名称。