Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Visual Studio theme styles for RichTextBox #391

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,32 @@
</local:ThemedControl.Disabled>
</local:ThemedControl>

<local:ThemedControl Label="RichTextBox:">
<local:ThemedControl.Enabled>
<RichTextBox>
<FlowDocument>
<Paragraph>
Rich
<Bold>Text</Bold>
<Italic>Box</Italic>
</Paragraph>
</FlowDocument>
</RichTextBox>
</local:ThemedControl.Enabled>

<local:ThemedControl.Disabled>
<RichTextBox IsEnabled="False">
<FlowDocument>
<Paragraph>
Rich
<Bold>Text</Bold>
<Italic>Box</Italic>
</Paragraph>
</FlowDocument>
</RichTextBox>
</local:ThemedControl.Disabled>
</local:ThemedControl>

<local:ThemedControl Label="PasswordBox:">
<local:ThemedControl.Enabled>
<PasswordBox Password="Password" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,58 @@
</Style.Triggers>
</Style>

<ControlTemplate x:Key="{x:Static local:ToolkitResourceKeys.RichTextBoxControlTemplateKey}" TargetType="{x:Type RichTextBox}">
<!--
The default template for a RichTextBox defines a trigger for IsMouseOver that changes the
border brush. To get our style triggers to apply, we need to override the template.
-->
<Border
x:Name="border"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
>

<ScrollViewer
x:Name="PART_ContentHost"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
/>
</Border>
</ControlTemplate>

<Style x:Key="{x:Static local:ToolkitResourceKeys.RichTextBoxStyleKey}" TargetType="RichTextBox">
<Setter Property="Padding" Value="{StaticResource {x:Static local:ToolkitResourceKeys.InputPaddingKey}}" />
<Setter Property="Background" Value="{DynamicResource {x:Static local:InternalResourceKeys.CommonControlsColors_TextBoxBackgroundBrushKey}}" />
<Setter Property="Foreground" Value="{DynamicResource {x:Static local:InternalResourceKeys.CommonControlsColors_TextBoxTextBrushKey}}" />
<Setter Property="BorderBrush" Value="{DynamicResource {x:Static local:InternalResourceKeys.CommonControlsColors_TextBoxBorderBrushKey}}" />

<Setter Property="Template" Value="{StaticResource {x:Static local:ToolkitResourceKeys.RichTextBoxControlTemplateKey}}"/>

<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{DynamicResource {x:Static local:InternalResourceKeys.CommonControlsColors_TextBoxBackgroundBrushKey}}" />
<Setter Property="Foreground" Value="{DynamicResource {x:Static local:InternalResourceKeys.CommonControlsColors_TextBoxTextBrushKey}}" />
<Setter Property="BorderBrush" Value="{DynamicResource {x:Static local:InternalResourceKeys.CommonControlsColors_TextBoxBorderBrushKey}}" />
</Trigger>

<Trigger Property="IsFocused" Value="True">
<Setter Property="Background" Value="{DynamicResource {x:Static local:InternalResourceKeys.CommonControlsColors_TextBoxBackgroundFocusedBrushKey}}" />
<Setter Property="Foreground" Value="{DynamicResource {x:Static local:InternalResourceKeys.CommonControlsColors_TextBoxTextFocusedBrushKey}}" />
<Setter Property="BorderBrush" Value="{DynamicResource {x:Static local:InternalResourceKeys.CommonControlsColors_TextBoxBorderFocusedBrushKey}}" />
</Trigger>

<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background" Value="{DynamicResource {x:Static local:InternalResourceKeys.CommonControlsColors_TextBoxBackgroundDisabledBrushKey}}" />
<Setter Property="Foreground" Value="{DynamicResource {x:Static local:InternalResourceKeys.CommonControlsColors_TextBoxTextDisabledBrushKey}}" />
<Setter Property="BorderBrush" Value="{DynamicResource {x:Static local:InternalResourceKeys.CommonControlsColors_TextBoxBorderDisabledBrushKey}}" />
</Trigger>
</Style.Triggers>
</Style>

<!-- Default styles. -->
<Style TargetType="TextBox" BasedOn="{StaticResource {x:Static local:ToolkitResourceKeys.TextBoxStyleKey}}" />
<Style TargetType="ComboBox" BasedOn="{StaticResource {x:Static local:ToolkitResourceKeys.ComboBoxStyleKey}}" />
<Style TargetType="PasswordBox" BasedOn="{StaticResource {x:Static local:ToolkitResourceKeys.PasswordBoxStyleKey}}" />
<Style TargetType="RichTextBox" BasedOn="{StaticResource {x:Static local:ToolkitResourceKeys.RichTextBoxStyleKey}}" />
</ResourceDictionary>
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,15 @@ public static class ToolkitResourceKeys
/// <summary>Gets the key that defines the resource for the <see cref="ControlTemplate"/> of a Visual Studio-themed <see cref="PasswordBox"/> style.</summary>
public static object PasswordBoxControlTemplateKey { get; } = _prefix + nameof(PasswordBoxControlTemplateKey);

/// <summary>Gets the key that defines the resource for a Visual Studio-themed <see cref="RichTextBox"/> style.</summary>
public static object RichTextBoxStyleKey { get; } = _prefix + nameof(RichTextBoxStyleKey);

/// <summary>Gets the key that defines the resource for the <see cref="ControlTemplate"/> of a Visual Studio-themed <see cref="RichTextBox"/> style.</summary>
public static object RichTextBoxControlTemplateKey { get; } = _prefix + nameof(RichTextBoxControlTemplateKey);

private static Uri BuildPackUri(string resource)
{
// Multiple versions of the toolkti assembly might be loaded, so when
// Multiple versions of the toolkit assembly might be loaded, so when
// loading a resource, we need to include the version number of this
// assembly to ensure that the resource is loaded from the correct assembly.
AssemblyName assemblyName = typeof(ToolkitResourceKeys).Assembly.GetName();
Expand Down