Skip to content

Commit 2020952

Browse files
Merge pull request #391 from reduckted/feature/rich-text-box-theme
Added Visual Studio theme styles for RichTextBox
2 parents 688428c + 40d9054 commit 2020952

File tree

3 files changed

+83
-1
lines changed

3 files changed

+83
-1
lines changed

demo/VSSDK.TestExtension/ToolWindows/ThemeWindow/ThemeWindowDemo.xaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,32 @@
8181
</local:ThemedControl.Disabled>
8282
</local:ThemedControl>
8383

84+
<local:ThemedControl Label="RichTextBox:">
85+
<local:ThemedControl.Enabled>
86+
<RichTextBox>
87+
<FlowDocument>
88+
<Paragraph>
89+
Rich
90+
<Bold>Text</Bold>
91+
<Italic>Box</Italic>
92+
</Paragraph>
93+
</FlowDocument>
94+
</RichTextBox>
95+
</local:ThemedControl.Enabled>
96+
97+
<local:ThemedControl.Disabled>
98+
<RichTextBox IsEnabled="False">
99+
<FlowDocument>
100+
<Paragraph>
101+
Rich
102+
<Bold>Text</Bold>
103+
<Italic>Box</Italic>
104+
</Paragraph>
105+
</FlowDocument>
106+
</RichTextBox>
107+
</local:ThemedControl.Disabled>
108+
</local:ThemedControl>
109+
84110
<local:ThemedControl Label="PasswordBox:">
85111
<local:ThemedControl.Enabled>
86112
<PasswordBox Password="Password" />

src/toolkit/Community.VisualStudio.Toolkit.Shared/Themes/ThemeResources.xaml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,58 @@
6565
</Style.Triggers>
6666
</Style>
6767

68+
<ControlTemplate x:Key="{x:Static local:ToolkitResourceKeys.RichTextBoxControlTemplateKey}" TargetType="{x:Type RichTextBox}">
69+
<!--
70+
The default template for a RichTextBox defines a trigger for IsMouseOver that changes the
71+
border brush. To get our style triggers to apply, we need to override the template.
72+
-->
73+
<Border
74+
x:Name="border"
75+
BorderBrush="{TemplateBinding BorderBrush}"
76+
BorderThickness="{TemplateBinding BorderThickness}"
77+
Background="{TemplateBinding Background}"
78+
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
79+
>
80+
81+
<ScrollViewer
82+
x:Name="PART_ContentHost"
83+
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
84+
/>
85+
</Border>
86+
</ControlTemplate>
87+
88+
<Style x:Key="{x:Static local:ToolkitResourceKeys.RichTextBoxStyleKey}" TargetType="RichTextBox">
89+
<Setter Property="Padding" Value="{StaticResource {x:Static local:ToolkitResourceKeys.InputPaddingKey}}" />
90+
<Setter Property="Background" Value="{DynamicResource {x:Static local:InternalResourceKeys.CommonControlsColors_TextBoxBackgroundBrushKey}}" />
91+
<Setter Property="Foreground" Value="{DynamicResource {x:Static local:InternalResourceKeys.CommonControlsColors_TextBoxTextBrushKey}}" />
92+
<Setter Property="BorderBrush" Value="{DynamicResource {x:Static local:InternalResourceKeys.CommonControlsColors_TextBoxBorderBrushKey}}" />
93+
94+
<Setter Property="Template" Value="{StaticResource {x:Static local:ToolkitResourceKeys.RichTextBoxControlTemplateKey}}"/>
95+
96+
<Style.Triggers>
97+
<Trigger Property="IsMouseOver" Value="True">
98+
<Setter Property="Background" Value="{DynamicResource {x:Static local:InternalResourceKeys.CommonControlsColors_TextBoxBackgroundBrushKey}}" />
99+
<Setter Property="Foreground" Value="{DynamicResource {x:Static local:InternalResourceKeys.CommonControlsColors_TextBoxTextBrushKey}}" />
100+
<Setter Property="BorderBrush" Value="{DynamicResource {x:Static local:InternalResourceKeys.CommonControlsColors_TextBoxBorderBrushKey}}" />
101+
</Trigger>
102+
103+
<Trigger Property="IsFocused" Value="True">
104+
<Setter Property="Background" Value="{DynamicResource {x:Static local:InternalResourceKeys.CommonControlsColors_TextBoxBackgroundFocusedBrushKey}}" />
105+
<Setter Property="Foreground" Value="{DynamicResource {x:Static local:InternalResourceKeys.CommonControlsColors_TextBoxTextFocusedBrushKey}}" />
106+
<Setter Property="BorderBrush" Value="{DynamicResource {x:Static local:InternalResourceKeys.CommonControlsColors_TextBoxBorderFocusedBrushKey}}" />
107+
</Trigger>
108+
109+
<Trigger Property="IsEnabled" Value="False">
110+
<Setter Property="Background" Value="{DynamicResource {x:Static local:InternalResourceKeys.CommonControlsColors_TextBoxBackgroundDisabledBrushKey}}" />
111+
<Setter Property="Foreground" Value="{DynamicResource {x:Static local:InternalResourceKeys.CommonControlsColors_TextBoxTextDisabledBrushKey}}" />
112+
<Setter Property="BorderBrush" Value="{DynamicResource {x:Static local:InternalResourceKeys.CommonControlsColors_TextBoxBorderDisabledBrushKey}}" />
113+
</Trigger>
114+
</Style.Triggers>
115+
</Style>
116+
68117
<!-- Default styles. -->
69118
<Style TargetType="TextBox" BasedOn="{StaticResource {x:Static local:ToolkitResourceKeys.TextBoxStyleKey}}" />
70119
<Style TargetType="ComboBox" BasedOn="{StaticResource {x:Static local:ToolkitResourceKeys.ComboBoxStyleKey}}" />
71120
<Style TargetType="PasswordBox" BasedOn="{StaticResource {x:Static local:ToolkitResourceKeys.PasswordBoxStyleKey}}" />
121+
<Style TargetType="RichTextBox" BasedOn="{StaticResource {x:Static local:ToolkitResourceKeys.RichTextBoxStyleKey}}" />
72122
</ResourceDictionary>

src/toolkit/Community.VisualStudio.Toolkit.Shared/Themes/ToolkitResourceKeys.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,15 @@ public static class ToolkitResourceKeys
4747
/// <summary>Gets the key that defines the resource for the <see cref="ControlTemplate"/> of a Visual Studio-themed <see cref="PasswordBox"/> style.</summary>
4848
public static object PasswordBoxControlTemplateKey { get; } = _prefix + nameof(PasswordBoxControlTemplateKey);
4949

50+
/// <summary>Gets the key that defines the resource for a Visual Studio-themed <see cref="RichTextBox"/> style.</summary>
51+
public static object RichTextBoxStyleKey { get; } = _prefix + nameof(RichTextBoxStyleKey);
52+
53+
/// <summary>Gets the key that defines the resource for the <see cref="ControlTemplate"/> of a Visual Studio-themed <see cref="RichTextBox"/> style.</summary>
54+
public static object RichTextBoxControlTemplateKey { get; } = _prefix + nameof(RichTextBoxControlTemplateKey);
55+
5056
private static Uri BuildPackUri(string resource)
5157
{
52-
// Multiple versions of the toolkti assembly might be loaded, so when
58+
// Multiple versions of the toolkit assembly might be loaded, so when
5359
// loading a resource, we need to include the version number of this
5460
// assembly to ensure that the resource is loaded from the correct assembly.
5561
AssemblyName assemblyName = typeof(ToolkitResourceKeys).Assembly.GetName();

0 commit comments

Comments
 (0)