如何将当前VS主题应用于现有控件

问题描述 投票:2回答:1

我正在使用的应用程序有一个桌面版本和一个Visual Studio扩展版本,两者大致提供相同的功能,因此重用相同的WPF控件集。这些控件驻留在WPF控件库中。一切都按预期工作。

最近我发现如果我将Visual Studio切换到黑暗主题,扩展名看起来不太好。我用Google搜索的解决方案是使用Visual Studio的内置画笔和颜色。

我怎么做?我的控件具有深层嵌套的样式和颜色。如果我在VS扩展中创建其他样式,WPF仍将应用控件内定义的本地笔刷和值。如何解决这个问题?

c# wpf visual-studio vsix vs-extensibility
1个回答
0
投票

您可以使用Visual Studio的画笔和颜色,如下所示:

<UserControl ... 
    xmlns:vsShell="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.14.0">

<TextBox Foreground="{DynamicResource {x:Static vsShell:EnvironmentColors.ToolWindowTextBrushKey}}" />

您还可以使用ThemeResourceKey检查哪个VS主题处于活动状态,该主题在所有VS主题(如AccentBorderColorKey)中具有不同的颜色,并检查返回的颜色。

var color = VSColorTheme.GetThemedColor(EnvironmentColors.AccentBorderColorKey);

enter image description here

并为WPF控件分配自己的(更好看的)颜色。

文档:

ThemeResouceKey

VSColorTheme.GetThemedColor

额外:

这可能有助于选择正确的ThemeResourceKey

VS Colors

© www.soinside.com 2019 - 2024. All rights reserved.