I'm developing a VS extension and I want to achieve that my UI will use colors (font, background etc.) depending on the selected VS-color-scheme. What is the best way to do this. Can I bind against some static ressources in my WPF?
Asked
Active
Viewed 3,912 times
1 Answers
21
Yes, binding to static VS resources is the best approach. It is supported in VS 2012+ and looks like this:
<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 all avilable colors.

Sergey Vlasov
- 26,641
- 3
- 64
- 66
-
– Can PERK Oct 19 '20 at 15:26
-
@CanPERK See for example https://github.com/Samsung/vs-tools-cps/blob/60d854051bbbe8bf5287f9d7e73988fd8c1127f6/src/Profiler/NetCore.Profiler.Extension/UI/Styles.xaml – Sergey Vlasov Oct 25 '20 at 07:00