Visual Studio扩展中的颜色

Ale*_*idt 12 wpf color-scheme visual-studio vsix

我正在开发一个VS扩展,我希望实现我的UI将使用颜色(字体,背景等),具体取决于所选的VS颜色方案.做这个的最好方式是什么.我可以绑定WPF中的一些静态资源吗?

Ser*_*sov 18

是的,绑定到静态VS资源是最好的方法.它在VS 2012+中受支持,如下所示:

<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>
Run Code Online (Sandbox Code Playgroud)

有关所有可用颜色,请参阅EnvironmentColors类.