Visual Studio Team Services

Retrieve and customize Tooling experience for User-selected Visual Studio Theme

Visual Studio 2012 introduced a new customization option for users that initially allowed them to choose either a Dark or a Light Theme (underneath Tools > Options > Environment > General > Color Theme), one of the later Updates (1 or 2 as far as I remember) brought a 3rd one, Blue (see examples over here).

For Developers writing Visual Studio Extensions that have an Ui component this makes life a bit more difficult as you might want to provide an user experience that feels natural and at home in any of these styles.

Carlos J. Quintero has, among a huge and thorough list of articles regarding VS extensibility, one particular one about how to retrieve the User selected theme available here.

At the time of writing the aforementioned Blue Theme was probably not yet available, but the corresponding CurrentTheme Guid is ’a4d6a176-b948-4b29-8c66-53c97a1ed7d0’, which makes all three to check for look like this:

  • Light theme: “de3dbbcd-f642-433c-8353-8f1df4370aba”
  • Dark theme: “1ded0138-47ce-435e-84ef-9ec1f439b749”
  • Blue Theme: “a4d6a176-b948-4b29-8c66-53c97a1ed7d0”

If you are certain that your users are only using one of the above you can easily check for either of them via the procedure outlined in Carlos’ article, there is however one caveat: VisualStudio allows users to create and use entirely custom ones.

Which means you are smarter off using the VS2012+ underlying EnvironmentColors API to retrieve the actual color values and also use them in your UserInterface, for example like this (via databinding directly to the API):

<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>

Discussion

Comments disabled.