Visual Studio扩展中的颜色

13

我正在开发一个VS扩展程序,希望我的UI能根据所选的VS颜色方案使用颜色(字体、背景等)。有什么最好的方法来实现这一点?我可以绑定一些静态资源到我的WPF上吗?

1个回答

21

绑定到静态的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 Class以获取所有可用颜色的信息。


按钮怎么办?特别是对于IsMouseOver,暗模式下的颜色太糟糕了。 - Can PERK
@CanPERK 例如,请参见 https://github.com/Samsung/vs-tools-cps/blob/60d854051bbbe8bf5287f9d7e73988fd8c1127f6/src/Profiler/NetCore.Profiler.Extension/UI/Styles.xaml - Sergey Vlasov

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接