12

我正在开发一个 VS 扩展,我想实现我的 UI 将根据所选的 VS-color-scheme 使用颜色(字体、背景等)。做这个的最好方式是什么。我可以在我的 WPF 中绑定一些静态资源吗?

4

1 回答 1

20

是的,绑定到静态 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>

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

于 2013-09-21T06:15:06.577 回答