12

私は VS 拡張機能を開発しており、選択した VS-color-scheme に応じて UI が色 (フォント、背景など) を使用するようにしたいと考えています。これを行う最善の方法は何ですか。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 に答える