我试图让我的申请力成为一个主题——这很简单,如下所示:http://arbel.net/blog/archive/2006/11/03/Forcing-WPF-to-use-a-specific-Windows-theme.aspx
但是,我不知道我现在使用的是什么主题。我正在使用 Windows XP 默认主题,不管它是什么。那篇文章说
It's important to specify the version and the public key token
...我从哪里获得该信息?
最佳答案
要获取主题名称,您可以调用非托管的 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)找到版本和公钥token(在Exporer中打开c:\Windows\Assembly),也可以使用代码实现.只需使用 AppDomain.CurrentDomain.LoadedAssemblies 遍历所有加载的程序集并找到您想要的程序集:
foreach(Assembly a in AppDomain.CurrentDomain.LoadedAssemblies)
if(a.Name.StartsWith("PresentationFramework."))
return a.FullName;
请注意,如果当前 AppDomain 中仅加载了一个主题,则遍历加载的程序集还会告诉您当前主题名称。
关于c# - 我如何知道我使用的是什么 Windows 主题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2977421/