创建 VSIX 工具窗口时如何匹配 Visual Studio 的主题? [英] How can I match Visual Studio's theme when creating a VSIX tool window?

查看:38
本文介绍了创建 VSIX 工具窗口时如何匹配 Visual Studio 的主题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 Visual Studio (2012+) 创建一个涉及工具窗口的扩展.我希望为窗口设置相同的样式以匹配 Visual Studio 的当前主题.但是,我在弄清楚如何去做时遇到了很多麻烦.

I am creating an extension for Visual Studio (2012+) that involves a tool window. I was hoping to style the window identically to match the current theme of Visual Studio. However, I am having a great deal of trouble figuring out how to do it.

这篇文章 表明完全不需要应用任何样式,但这与我迄今为止的经验不符(甚至在 VS2017 和添加一个工具窗口会显示一个按钮,我认为它是主题中的标准 WPF 而不是 VS 主题,至少在 VS2017 中使用深色 VS 主题时如此).

This post suggests that applying no style at all is all that is required, but that does not match my experience thus far (even creating a default VSIX project in VS2017 and adding a tool window shows a button that I would argue is standard WPF in theme and not VS themed, at least when using the dark VS theme in VS2017).

这个帖子问了一个类似的问题,以及当时的解决方案似乎是使用免费工具包创建类似的控件.但是,那是针对 VS2012 和 6 年前的,我希望现在有更多可用的解决方案.走这条路似乎不太适合未来.

This post asked a similar question, and the solution at the time seemed to be to create similar controls using a free toolkit. However, that was for VS2012 and 6 years ago, and I'm hoping a solution is more available these days. It doesn't seem very future proof to take this route.

另一种解决方案是将 Visual Studio 的 VsBrushes 和 VsColors 应用于 WPF 控件.这可能让我找到了一些解决方案 - 但样式不仅仅是颜色,所以它似乎不太令人满意.

Another solution is to apply Visual Studio's VsBrushes and VsColors to WPF controls. This probably gets me some way to the solution - but styles are more than colors, so it doesn't seem very satisfactory.

有没有办法将 Visual Studio 的基本控件样式(按钮、文本框、列表视图、树视图等)应用到我的 VSIX 工具窗口,使其在 Visual Studio 中看起来和感觉就像在家一样?

Is there a way to apply Visual Studio's basic controls styles (button, text box, listview, treeview, etc.) to my VSIX tool window to make it look and feel at home in Visual Studio?

感谢您的建议!

推荐答案

如何在创建 VSIX 工具窗口时匹配 Visual Studio 的主题?

How can I match Visual Studio's theme when creating a VSIX tool window?

可以尝试绑定静态VS资源:

You can try to binding to static VS resources:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vs_shell="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.11.0">
<Style TargetType="Label">
    <Setter Property="Foreground" Value="{DynamicResource {x:Static vs_shell:EnvironmentColors.ToolWindowTextBrushKey}}"/>
</Style>
<Style TargetType="TextBox">
    <Setter Property="Foreground" Value="{DynamicResource {x:Static vs_shell:EnvironmentColors.ToolWindowTextBrushKey}}"/>
    <Setter Property="Background" Value="{DynamicResource {x:Static vs_shell:EnvironmentColors.ToolWindowBackgroundBrushKey}}"/>
</Style>
</ResourceDictionary>

请参阅 EnvironmentColors 类了解更多详情.

See EnvironmentColors Class for more details.

注意:要获得完全相同的主题,您需要使用 VS 使用的完全相同的 XAML.谢谢@GrantTheAnt.

Note: To get the exactly the same theme, you need use the exact XAML that VS uses. Thanks @GrantTheAnt.

这篇关于创建 VSIX 工具窗口时如何匹配 Visual Studio 的主题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆