Ada*_*m S 3 c# windows wpf windows-themes
我试图使我的应用程序成为主题,这很简单,如下所示: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);
Run Code Online (Sandbox Code Playgroud)
您可以通过右键单击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;
Run Code Online (Sandbox Code Playgroud)
请注意,如果在当前AppDomain中仅加载了一个主题,则遍历已加载的程序集也会告诉您当前的主题名称。
| 归档时间: |
|
| 查看次数: |
1845 次 |
| 最近记录: |