Skip to content

Commit 323c3f9

Browse files
authored
Fixes layout issues in RichTextBox style for Fluent theme (#10793)
* Fixes layout issues in RichTextBox style for Fluent theme * Removed commented old style
1 parent 5edc518 commit 323c3f9

File tree

4 files changed

+162
-120
lines changed

4 files changed

+162
-120
lines changed

src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Fluent/Styles/RichTextBox.xaml

Lines changed: 54 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,71 +7,80 @@
77

88
<ResourceDictionary
99
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
10-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
11-
10+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
11+
xmlns:system="clr-namespace:System;assembly=System.Runtime" >
12+
13+
<!-- Deprecated RichTextBox Resources ( Used in .NET 9 ) -->
1214
<Thickness x:Key="RichTextBoxAccentBorderThemeThickness">0,0,0,1</Thickness>
15+
16+
<!-- Instead of RichTextBoxThemeMinHeight, we need to use TextControlThemeMinHeight, but modifying that right now
17+
will affect the other styles as well. Once the remaining styles using it are fixed, will remove this resource -->
18+
<system:Double x:Key="RichTextBoxThemeMinHeight">32</system:Double>
1319

1420
<Style x:Key="DefaultRichTextBoxStyle" TargetType="{x:Type RichTextBox}">
21+
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
22+
<Setter Property="ContextMenu" Value="{DynamicResource DefaultControlContextMenu}" />
1523
<Setter Property="Foreground" Value="{DynamicResource TextControlForeground}" />
1624
<Setter Property="CaretBrush" Value="{DynamicResource TextControlForeground}" />
1725
<Setter Property="Background" Value="{DynamicResource TextControlBackground}" />
18-
<Setter Property="BorderBrush" Value="{DynamicResource TextControlElevationBorderBrush}" />
19-
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
20-
<Setter Property="VerticalScrollBarVisibility" Value="Auto" />
21-
<Setter Property="HorizontalScrollBarVisibility" Value="Disabled" />
22-
<Setter Property="HorizontalAlignment" Value="Stretch" />
23-
<Setter Property="VerticalAlignment" Value="Stretch" />
24-
<Setter Property="MinHeight" Value="34" />
25-
<Setter Property="BorderThickness" Value="1" />
26-
<Setter Property="Padding" Value="6,4" />
27-
<Setter Property="SnapsToDevicePixels" Value="True" />
26+
<Setter Property="BorderBrush" Value="{DynamicResource TextControlBorderBrush}" />
27+
<Setter Property="BorderThickness" Value="{StaticResource TextControlBorderThemeThickness}" />
28+
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" />
29+
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
30+
<Setter Property="HorizontalContentAlignment" Value="Left" />
31+
<Setter Property="VerticalContentAlignment" Value="Top" />
32+
<Setter Property="Cursor" Value="IBeam" />
33+
<Setter Property="MinHeight" Value="{DynamicResource RichTextBoxThemeMinHeight}" />
34+
<Setter Property="MinWidth" Value="{DynamicResource TextControlThemeMinWidth}" />
35+
<Setter Property="Padding" Value="{DynamicResource TextControlThemePadding}" />
36+
<Setter Property="Border.CornerRadius" Value="{DynamicResource ControlCornerRadius}" />
37+
<Setter Property="AllowDrop" Value="True"/>
38+
<Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
39+
<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
2840
<Setter Property="OverridesDefaultStyle" Value="True" />
2941
<Setter Property="Template">
3042
<Setter.Value>
3143
<ControlTemplate TargetType="{x:Type RichTextBox}">
3244
<Grid>
3345
<Border
34-
x:Name="MainBorder"
35-
Padding="0"
46+
x:Name="ContentBorder"
47+
MinWidth="{TemplateBinding MinWidth}"
48+
MinHeight="{TemplateBinding MinHeight}"
3649
Background="{TemplateBinding Background}"
3750
BorderBrush="{TemplateBinding BorderBrush}"
3851
BorderThickness="{TemplateBinding BorderThickness}"
39-
CornerRadius="4"
40-
Focusable="False">
41-
<ScrollViewer
42-
x:Name="PART_ContentHost"
43-
Margin="0,0,2,0"
44-
Padding="{TemplateBinding Padding}"
45-
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
46-
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
47-
Foreground="{TemplateBinding Foreground}"
48-
HorizontalScrollBarVisibility="{TemplateBinding HorizontalScrollBarVisibility}"
49-
VerticalScrollBarVisibility="{TemplateBinding VerticalScrollBarVisibility}" />
50-
</Border>
51-
<Border
52-
x:Name="AccentBorder"
53-
HorizontalAlignment="Stretch"
54-
VerticalAlignment="Stretch"
55-
BorderBrush="{DynamicResource ControlStrokeColorDefaultBrush}"
56-
BorderThickness="{StaticResource RichTextBoxAccentBorderThemeThickness}"
57-
CornerRadius="{DynamicResource ControlCornerRadius}" />
52+
CornerRadius="{TemplateBinding Border.CornerRadius}" />
53+
54+
<ScrollViewer
55+
x:Name="PART_ContentHost"
56+
Margin="{TemplateBinding BorderThickness}"
57+
CanContentScroll="{TemplateBinding ScrollViewer.CanContentScroll}"
58+
HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
59+
IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}"
60+
IsTabStop="{TemplateBinding ScrollViewer.IsTabStop}"
61+
Padding="{TemplateBinding Padding}"
62+
TextElement.Foreground="{TemplateBinding Foreground}"
63+
VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}" />
5864
</Grid>
5965
<ControlTemplate.Triggers>
60-
<MultiTrigger>
61-
<MultiTrigger.Conditions>
62-
<Condition Property="IsEnabled" Value="True" />
63-
<Condition Property="IsMouseOver" Value="True" />
64-
<Condition Property="IsFocused" Value="False" />
65-
</MultiTrigger.Conditions>
66-
<Setter Property="Background" Value="{DynamicResource TextControlBackgroundPointerOver}" />
67-
</MultiTrigger>
66+
<Trigger Property="IsMouseOver" Value="True">
67+
<Setter TargetName="ContentBorder" Property="Background" Value="{DynamicResource TextControlBackgroundPointerOver}" />
68+
<Setter TargetName="ContentBorder" Property="BorderBrush" Value="{DynamicResource TextControlBorderBrushPointerOver}" />
69+
<Setter TargetName="PART_ContentHost" Property="Foreground" Value="{DynamicResource TextControlForegroundPointerOver}" />
70+
</Trigger>
6871
<Trigger Property="IsFocused" Value="True">
69-
<Setter TargetName="AccentBorder" Property="BorderThickness" Value="0,0,0,2" />
70-
<Setter TargetName="AccentBorder" Property="BorderBrush" Value="{DynamicResource TextControlFocusedBorderBrush}" />
71-
<Setter Property="Background" Value="{DynamicResource TextControlBackgroundFocused}" />
72+
<Setter TargetName="ContentBorder" Property="BorderThickness" Value="{StaticResource TextControlBorderThemeThicknessFocused}" />
73+
<Setter TargetName="ContentBorder" Property="Background" Value="{DynamicResource TextControlBackgroundFocused}" />
74+
<Setter TargetName="ContentBorder" Property="BorderBrush" Value="{DynamicResource TextControlBorderBrushFocused}" />
75+
<Setter TargetName="PART_ContentHost" Property="Foreground" Value="{DynamicResource TextControlForegroundFocused}" />
76+
</Trigger>
77+
<Trigger Property="IsEnabled" Value="False">
78+
<Setter TargetName="ContentBorder" Property="Background" Value="{DynamicResource TextControlBackgroundDisabled}" />
79+
<Setter TargetName="ContentBorder" Property="BorderBrush" Value="{DynamicResource TextControlBorderBrushDisabled}" />
80+
<Setter TargetName="PART_ContentHost" Property="Foreground" Value="{DynamicResource TextControlForegroundDisabled}" />
7281
</Trigger>
7382
</ControlTemplate.Triggers>
74-
</ControlTemplate>
83+
</ControlTemplate>
7584
</Setter.Value>
7685
</Setter>
7786
</Style>

src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Fluent/Themes/Fluent.Dark.xaml

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4067,44 +4067,55 @@
40674067
</Setter>
40684068
</Style>
40694069
<Style BasedOn="{StaticResource DefaultResizeGripStyle}" TargetType="{x:Type ResizeGrip}" />
4070+
<!-- Deprecated RichTextBox Resources ( Used in .NET 9 ) -->
40704071
<Thickness x:Key="RichTextBoxAccentBorderThemeThickness">0,0,0,1</Thickness>
4072+
<!-- Instead of RichTextBoxThemeMinHeight, we need to use TextControlThemeMinHeight, but modifying that right now
4073+
will affect the other styles as well. Once the remaining styles using it are fixed, will remove this resource -->
4074+
<system:Double x:Key="RichTextBoxThemeMinHeight">32</system:Double>
40714075
<Style x:Key="DefaultRichTextBoxStyle" TargetType="{x:Type RichTextBox}">
4076+
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
4077+
<Setter Property="ContextMenu" Value="{DynamicResource DefaultControlContextMenu}" />
40724078
<Setter Property="Foreground" Value="{DynamicResource TextControlForeground}" />
40734079
<Setter Property="CaretBrush" Value="{DynamicResource TextControlForeground}" />
40744080
<Setter Property="Background" Value="{DynamicResource TextControlBackground}" />
4075-
<Setter Property="BorderBrush" Value="{DynamicResource TextControlElevationBorderBrush}" />
4076-
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
4077-
<Setter Property="VerticalScrollBarVisibility" Value="Auto" />
4078-
<Setter Property="HorizontalScrollBarVisibility" Value="Disabled" />
4079-
<Setter Property="HorizontalAlignment" Value="Stretch" />
4080-
<Setter Property="VerticalAlignment" Value="Stretch" />
4081-
<Setter Property="MinHeight" Value="34" />
4082-
<Setter Property="BorderThickness" Value="1" />
4083-
<Setter Property="Padding" Value="6,4" />
4084-
<Setter Property="SnapsToDevicePixels" Value="True" />
4081+
<Setter Property="BorderBrush" Value="{DynamicResource TextControlBorderBrush}" />
4082+
<Setter Property="BorderThickness" Value="{StaticResource TextControlBorderThemeThickness}" />
4083+
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" />
4084+
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
4085+
<Setter Property="HorizontalContentAlignment" Value="Left" />
4086+
<Setter Property="VerticalContentAlignment" Value="Top" />
4087+
<Setter Property="Cursor" Value="IBeam" />
4088+
<Setter Property="MinHeight" Value="{DynamicResource RichTextBoxThemeMinHeight}" />
4089+
<Setter Property="MinWidth" Value="{DynamicResource TextControlThemeMinWidth}" />
4090+
<Setter Property="Padding" Value="{DynamicResource TextControlThemePadding}" />
4091+
<Setter Property="Border.CornerRadius" Value="{DynamicResource ControlCornerRadius}" />
4092+
<Setter Property="AllowDrop" Value="True" />
4093+
<Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst" />
4094+
<Setter Property="Stylus.IsFlicksEnabled" Value="False" />
40854095
<Setter Property="OverridesDefaultStyle" Value="True" />
40864096
<Setter Property="Template">
40874097
<Setter.Value>
40884098
<ControlTemplate TargetType="{x:Type RichTextBox}">
40894099
<Grid>
4090-
<Border x:Name="MainBorder" Padding="0" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="4" Focusable="False">
4091-
<ScrollViewer x:Name="PART_ContentHost" Margin="0,0,2,0" Padding="{TemplateBinding Padding}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Foreground="{TemplateBinding Foreground}" HorizontalScrollBarVisibility="{TemplateBinding HorizontalScrollBarVisibility}" VerticalScrollBarVisibility="{TemplateBinding VerticalScrollBarVisibility}" />
4092-
</Border>
4093-
<Border x:Name="AccentBorder" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" BorderBrush="{DynamicResource ControlStrokeColorDefaultBrush}" BorderThickness="{StaticResource RichTextBoxAccentBorderThemeThickness}" CornerRadius="{DynamicResource ControlCornerRadius}" />
4100+
<Border x:Name="ContentBorder" MinWidth="{TemplateBinding MinWidth}" MinHeight="{TemplateBinding MinHeight}" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="{TemplateBinding Border.CornerRadius}" />
4101+
<ScrollViewer x:Name="PART_ContentHost" Margin="{TemplateBinding BorderThickness}" CanContentScroll="{TemplateBinding ScrollViewer.CanContentScroll}" HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}" IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}" IsTabStop="{TemplateBinding ScrollViewer.IsTabStop}" Padding="{TemplateBinding Padding}" TextElement.Foreground="{TemplateBinding Foreground}" VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}" />
40944102
</Grid>
40954103
<ControlTemplate.Triggers>
4096-
<MultiTrigger>
4097-
<MultiTrigger.Conditions>
4098-
<Condition Property="IsEnabled" Value="True" />
4099-
<Condition Property="IsMouseOver" Value="True" />
4100-
<Condition Property="IsFocused" Value="False" />
4101-
</MultiTrigger.Conditions>
4102-
<Setter Property="Background" Value="{DynamicResource TextControlBackgroundPointerOver}" />
4103-
</MultiTrigger>
4104+
<Trigger Property="IsMouseOver" Value="True">
4105+
<Setter TargetName="ContentBorder" Property="Background" Value="{DynamicResource TextControlBackgroundPointerOver}" />
4106+
<Setter TargetName="ContentBorder" Property="BorderBrush" Value="{DynamicResource TextControlBorderBrushPointerOver}" />
4107+
<Setter TargetName="PART_ContentHost" Property="Foreground" Value="{DynamicResource TextControlForegroundPointerOver}" />
4108+
</Trigger>
41044109
<Trigger Property="IsFocused" Value="True">
4105-
<Setter TargetName="AccentBorder" Property="BorderThickness" Value="0,0,0,2" />
4106-
<Setter TargetName="AccentBorder" Property="BorderBrush" Value="{DynamicResource TextControlFocusedBorderBrush}" />
4107-
<Setter Property="Background" Value="{DynamicResource TextControlBackgroundFocused}" />
4110+
<Setter TargetName="ContentBorder" Property="BorderThickness" Value="{StaticResource TextControlBorderThemeThicknessFocused}" />
4111+
<Setter TargetName="ContentBorder" Property="Background" Value="{DynamicResource TextControlBackgroundFocused}" />
4112+
<Setter TargetName="ContentBorder" Property="BorderBrush" Value="{DynamicResource TextControlBorderBrushFocused}" />
4113+
<Setter TargetName="PART_ContentHost" Property="Foreground" Value="{DynamicResource TextControlForegroundFocused}" />
4114+
</Trigger>
4115+
<Trigger Property="IsEnabled" Value="False">
4116+
<Setter TargetName="ContentBorder" Property="Background" Value="{DynamicResource TextControlBackgroundDisabled}" />
4117+
<Setter TargetName="ContentBorder" Property="BorderBrush" Value="{DynamicResource TextControlBorderBrushDisabled}" />
4118+
<Setter TargetName="PART_ContentHost" Property="Foreground" Value="{DynamicResource TextControlForegroundDisabled}" />
41084119
</Trigger>
41094120
</ControlTemplate.Triggers>
41104121
</ControlTemplate>

0 commit comments

Comments
 (0)