Browse Source

Merge pull request #11364 from AvaloniaUI/fix-selectiontextblock-selectionbrush-color

Use correct theme specific selection brush on SelectableTextBlock
Max Katz 2 năm trước cách đây
mục cha
commit
6277b3e555

+ 1 - 1
samples/ControlCatalog/Pages/TextBlockPage.xaml

@@ -118,7 +118,7 @@
         </StackPanel>
       </Border>
       <Border>
-        <SelectableTextBlock SelectionBrush="LightBlue" Margin="10" TextWrapping="Wrap">
+        <SelectableTextBlock Margin="10" TextWrapping="Wrap">
           This <Span FontWeight="Bold">is</Span> a
           <Span Background="Silver" Foreground="Maroon">TextBlock</Span>
           with <Span TextDecorations="Underline">several</Span>

+ 1 - 1
src/Avalonia.Controls/SelectableTextBlock.cs

@@ -30,7 +30,7 @@ namespace Avalonia.Controls
                 o => o.SelectedText);
 
         public static readonly StyledProperty<IBrush?> SelectionBrushProperty =
-            TextBox.SelectionBrushProperty.AddOwner<SelectableTextBlock>(new(new Data.Optional<IBrush?>(Brushes.Blue)));
+            TextBox.SelectionBrushProperty.AddOwner<SelectableTextBlock>();
 
         public static readonly DirectProperty<SelectableTextBlock, bool> CanCopyProperty =
             TextBox.CanCopyProperty.AddOwner<SelectableTextBlock>(o => o.CanCopy);

+ 2 - 0
src/Avalonia.Themes.Fluent/Controls/SelectableTextBlock.xaml

@@ -10,6 +10,8 @@
   </MenuFlyout>
 
   <ControlTheme x:Key="{x:Type SelectableTextBlock}" TargetType="SelectableTextBlock">
+    <Setter Property="SelectionBrush" Value="{DynamicResource TextControlSelectionHighlightColor}" />
+
     <Style Selector="^[IsEnabled=True]">
       <Setter Property="Cursor" Value="IBeam" />
       <Setter Property="ContextFlyout" Value="{StaticResource SelectableTextBlockContextFlyout}" />

+ 2 - 0
src/Avalonia.Themes.Simple/Controls/SelectableTextBlock.xaml

@@ -10,6 +10,8 @@
   </MenuFlyout>
 
   <ControlTheme x:Key="{x:Type SelectableTextBlock}" TargetType="SelectableTextBlock">
+    <Setter Property="SelectionBrush" Value="{DynamicResource HighlightBrush}" />
+
     <Style Selector="^[IsEnabled=True]">
       <Setter Property="Cursor" Value="IBeam" />
       <Setter Property="ContextFlyout" Value="{StaticResource SelectableTextBlockContextFlyout}" />