Wpf 开发Visual Studio扩展以获得当前的前景色
在我的WPF用户控件中,如果用户有一个黑色的主题,那么默认情况下,我的所有文本都是黑色的,很难阅读。使用VS当前颜色的正确方法是什么。您可以通过编写自己的Visual Studio风格画笔和与控件合并两种方法来完成 另一方面,您可以从Windows注册表中选择VS主题的资源。很久以前,我使用实用程序类从windows注册表中选择当前主题Wpf 开发Visual Studio扩展以获得当前的前景色,wpf,visual-studio,visual-studio-2013,Wpf,Visual Studio,Visual Studio 2013,在我的WPF用户控件中,如果用户有一个黑色的主题,那么默认情况下,我的所有文本都是黑色的,很难阅读。使用VS当前颜色的正确方法是什么。您可以通过编写自己的Visual Studio风格画笔和与控件合并两种方法来完成 另一方面,您可以从Windows注册表中选择VS主题的资源。很久以前,我使用实用程序类从windows注册表中选择当前主题 public enum VsTheme { Unknown = 0, Light, Dark, Blue } publi
public enum VsTheme
{
Unknown = 0,
Light,
Dark,
Blue
}
public class ThemeUtil
{
private static readonly IDictionary<string, VsTheme> Themes = new Dictionary<string, VsTheme>()
{
{ "de3dbbcd-f642-433c-8353-8f1df4370aba", VsTheme.Light },
{ "1ded0138-47ce-435e-84ef-9ec1f439b749", VsTheme.Dark },
{ "a4d6a176-b948-4b29-8c66-53c97a1ed7d0", VsTheme.Blue }
};
public static VsTheme GetCurrentTheme()
{
string themeId = GetThemeId();
if (string.IsNullOrWhiteSpace(themeId) == false)
{
VsTheme theme;
if (Themes.TryGetValue(themeId, out theme))
{
return theme;
}
}
return VsTheme.Unknown;
}
public static string GetThemeId()
{
const string CategoryName = "General";
const string ThemePropertyName = "CurrentTheme";
string keyName = string.Format(@"Software\Microsoft\VisualStudio\11.0\{0}", CategoryName);
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(keyName))
{
if (key != null)
{
return (string)key.GetValue(ThemePropertyName, string.Empty);
}
}
return null;
}
}
名称空间必须添加为
xmlns:vsfx="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.12.0"
您可以参考以下MSDN链接中的所有笔刷
如果要检测主题更改事件本身,可以使用VSColorTheme.ThemeChanged事件
您可以通过编写自己的Visual Studio风格画笔和与控件合并两种方式来完成 另一方面,您可以从Windows注册表中选择VS主题的资源。很久以前,我使用实用程序类从windows注册表中选择当前主题
public enum VsTheme
{
Unknown = 0,
Light,
Dark,
Blue
}
public class ThemeUtil
{
private static readonly IDictionary<string, VsTheme> Themes = new Dictionary<string, VsTheme>()
{
{ "de3dbbcd-f642-433c-8353-8f1df4370aba", VsTheme.Light },
{ "1ded0138-47ce-435e-84ef-9ec1f439b749", VsTheme.Dark },
{ "a4d6a176-b948-4b29-8c66-53c97a1ed7d0", VsTheme.Blue }
};
public static VsTheme GetCurrentTheme()
{
string themeId = GetThemeId();
if (string.IsNullOrWhiteSpace(themeId) == false)
{
VsTheme theme;
if (Themes.TryGetValue(themeId, out theme))
{
return theme;
}
}
return VsTheme.Unknown;
}
public static string GetThemeId()
{
const string CategoryName = "General";
const string ThemePropertyName = "CurrentTheme";
string keyName = string.Format(@"Software\Microsoft\VisualStudio\11.0\{0}", CategoryName);
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(keyName))
{
if (key != null)
{
return (string)key.GetValue(ThemePropertyName, string.Empty);
}
}
return null;
}
}
名称空间必须添加为
xmlns:vsfx="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.12.0"
您可以参考以下MSDN链接中的所有笔刷
如果要检测主题更改事件本身,可以使用VSColorTheme.ThemeChanged事件
ShineKing,返回当前主题。你能告诉我如何在Xaml中使用它吗?例如,如何基于它设置标签的颜色。Mohsen,我找到了另一种方法将VS的画笔直接引用到Xaml。当然对你有用。请看我编辑的代码Hi ShineKing,我想我仍然缺少一些东西。它仍然不起作用。你介意在某处分享你的解决方案吗?ShineKing,这是返回当前主题。你能告诉我如何在Xaml中使用它吗?例如,如何基于它设置标签的颜色。Mohsen,我找到了另一种方法将VS的画笔直接引用到Xaml。当然对你有用。请看我编辑的代码Hi ShineKing,我想我仍然缺少一些东西。它仍然不起作用。你介意在某处分享你的解决方案吗?ShineKing,这是返回当前主题。你能告诉我如何在Xaml中使用它吗?例如,如何基于它设置标签的颜色。Mohsen,我找到了另一种方法将VS的画笔直接引用到Xaml。当然对你有用。请看我编辑的代码Hi ShineKing,我想我仍然缺少一些东西。它仍然不起作用。你介意在什么地方分享你的解决方案吗。