c# - 我如何知道我使用的是什么 Windows 主题?

标签 c# wpf windows windows-themes

我试图让我的申请力成为一个主题——这很简单,如下所示: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/

相关文章:

c# - 使用 DataGridViewCheckBoxColumn 更新 DatagridView

c# - 如何在 XAML 页面之间传递值(参数)?

windows - socket 乒乓性能

android - 亚行外壳错误 : app_process not found

linux - 通过单个命令行操作确定操作系统

c# - 使用 C# Windows 窗体应用程序将过滤后的数据从 Crystal 报表导出到 pdf

c# - 如何填充 ItemsControl 中的外键字段?

c# - 如何在C#中获取类中的变量列表

c# - 如何从 2 个不同的程序集加载相同的插件,并在两者之间序列化和反序列化类型? C#.net

wpf - 如何将 wpf 应用程序转换为 exe