我试图使我的应用力量成为主题 - 这很简单,如下所示: http://arbel.net/blog/archive/2006/11/11/11/forcing-wpf-to-cus-s-pecific-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)(Open C: Windows indarder),找到版本和公共密钥令牌,或者您可以使用代码来执行此操作。只需使用AppDomain.CurrentDomain.loadedAssemblies循环浏览所有已加载的组件,然后找到您想要的一个:

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

请注意,通过已加载的组件循环也会告诉您当前的主题名称 如果 当前的AppDomain中仅加载了一个主题。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top