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.
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).
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.
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.
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?
Thanks for any suggestions!
On the menu bar, select Tools > Options. In the options list, select Environment > General. In the Color theme list, choose between the default Dark theme, the Blue theme, the Blue (Extra Contrast) theme, and the Light theme. Or, choose the Use system setting option to select the theme that Windows uses.
Select File > New > Project. In the search box, type "vsix" and select either the C# or Visual Basic version of VSIX Project.
How can I match Visual Studio's theme when creating a VSIX tool window?
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>
See EnvironmentColors Class for more details.
Note: To get the exactly the same theme, you need use the exact XAML that VS uses. Thanks @GrantTheAnt.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With