enhance: Optimized the ScrollViewer style.

This commit is contained in:
NaBian committed 2024-07-27 21:32:20 +08:00
1 parent 17c2b8473b
commit 51f07648ee
16 files changed
+458 -235

No files matched your search

@@ -0,0 +1,124 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ControlTheme x:Key="RepeatButtonBaseStyle"
TargetType="RepeatButton">
<Setter Property="Height"
Value="{StaticResource DefaultControlHeight}" />
<Setter Property="Padding"
Value="{StaticResource DefaultControlPadding}" />
<Setter Property="HorizontalAlignment"
Value="Center" />
<Setter Property="VerticalAlignment"
Value="Center" />
<Setter Property="HorizontalContentAlignment"
Value="Center" />
<Setter Property="VerticalContentAlignment"
Value="Center" />
<Setter Property="Background"
Value="{DynamicResource RegionBrush}" />
<Setter Property="Foreground"
Value="{DynamicResource TextIconBrush}" />
<Setter Property="BorderBrush"
Value="{DynamicResource BorderBrush}" />
<Setter Property="BorderThickness"
Value="1" />
<Setter Property="CornerRadius"
Value="{StaticResource DefaultCornerRadius}" />
<Setter Property="Template">
<ControlTemplate>
<ContentPresenter x:Name="PART_ContentPresenter"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Padding="{TemplateBinding Padding}"
RecognizesAccessKey="True"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" />
</ControlTemplate>
</Setter>
<Style Selector="^:pointerover /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Opacity"
Value="0.9" />
</Style>
<Style Selector="^:pressed /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Opacity"
Value="0.6" />
</Style>
<Style Selector="^:disabled /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Opacity"
Value="0.4" />
</Style>
</ControlTheme>
<ControlTheme x:Key="RepeatButtonDefault"
BasedOn="{StaticResource RepeatButtonBaseStyle}"
TargetType="RepeatButton">
<Setter Property="Foreground"
Value="{DynamicResource PrimaryTextBrush}" />
<Style Selector="^:pointerover /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Background"
Value="{DynamicResource SecondaryRegionBrush}" />
</Style>
<Style Selector="^:pressed /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Background"
Value="{DynamicResource BorderBrush}" />
</Style>
</ControlTheme>
<ControlTheme x:Key="{x:Type RepeatButton}"
BasedOn="{StaticResource RepeatButtonDefault}"
TargetType="RepeatButton" />
<ControlTheme x:Key="RepeatButtonPrimary"
BasedOn="{StaticResource RepeatButtonBaseStyle}"
TargetType="RepeatButton">
<Setter Property="Background"
Value="{DynamicResource PrimaryBrush}" />
<Setter Property="BorderBrush"
Value="{DynamicResource PrimaryBrush}" />
</ControlTheme>
<ControlTheme x:Key="RepeatButtonSuccess"
BasedOn="{StaticResource RepeatButtonBaseStyle}"
TargetType="RepeatButton">
<Setter Property="Background"
Value="{DynamicResource SuccessBrush}" />
<Setter Property="BorderBrush"
Value="{DynamicResource SuccessBrush}" />
</ControlTheme>
<ControlTheme x:Key="RepeatButtonInfo"
BasedOn="{StaticResource RepeatButtonBaseStyle}"
TargetType="RepeatButton">
<Setter Property="Background"
Value="{DynamicResource InfoBrush}" />
<Setter Property="BorderBrush"
Value="{DynamicResource InfoBrush}" />
</ControlTheme>
<ControlTheme x:Key="RepeatButtonWarning"
BasedOn="{StaticResource RepeatButtonBaseStyle}"
TargetType="RepeatButton">
<Setter Property="Background"
Value="{DynamicResource WarningBrush}" />
<Setter Property="BorderBrush"
Value="{DynamicResource WarningBrush}" />
</ControlTheme>
<ControlTheme x:Key="RepeatButtonDanger"
BasedOn="{StaticResource RepeatButtonBaseStyle}"
TargetType="RepeatButton">
<Setter Property="Background"
Value="{DynamicResource DangerBrush}" />
<Setter Property="BorderBrush"
Value="{DynamicResource DangerBrush}" />
</ControlTheme>
</ResourceDictionary>
@@ -1,173 +0,0 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ControlTheme x:Key="{x:Type ScrollBar}"
TargetType="ScrollBar">
<Setter Property="Cursor"
Value="Arrow" />
<Style Selector="^:horizontal">
<Setter Property="Height"
Value="{DynamicResource ScrollBarThickness}" />
<Setter Property="Template">
<ControlTemplate>
<Border Background="{DynamicResource ThemeControlMidBrush}"
UseLayoutRounding="False">
<Grid ColumnDefinitions="Auto,*,Auto"
RowDefinitions="*,*,*">
<RepeatButton Name="PART_LineUpButton"
Grid.Row="0"
Grid.Column="0"
MinWidth="{DynamicResource ScrollBarThickness}"
VerticalAlignment="Center"
Classes="repeat"
Focusable="False">
<Path Data="M 4 0 L 4 8 L 0 4 Z" />
</RepeatButton>
<Track Grid.Row="1"
Grid.Column="1"
Maximum="{TemplateBinding Maximum}"
Minimum="{TemplateBinding Minimum}"
Orientation="{TemplateBinding Orientation}"
ViewportSize="{TemplateBinding ViewportSize}"
DeferThumbDrag="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}"
Value="{TemplateBinding Value,
Mode=TwoWay}">
<Track.DecreaseButton>
<RepeatButton Name="PART_PageUpButton"
Classes="repeattrack"
Focusable="False" />
</Track.DecreaseButton>
<Track.IncreaseButton>
<RepeatButton Name="PART_PageDownButton"
Classes="repeattrack"
Focusable="False" />
</Track.IncreaseButton>
<Thumb Name="thumb" />
</Track>
<RepeatButton Name="PART_LineDownButton"
Grid.Row="2"
Grid.Column="2"
MinWidth="{DynamicResource ScrollBarThickness}"
VerticalAlignment="Center"
Classes="repeat"
Focusable="False">
<Path Data="M 0 0 L 4 4 L 0 8 Z" />
</RepeatButton>
</Grid>
</Border>
</ControlTemplate>
</Setter>
</Style>
<Style Selector="^:vertical">
<Setter Property="Width"
Value="{DynamicResource ScrollBarThickness}" />
<Setter Property="Template">
<ControlTemplate>
<Border Background="{DynamicResource ThemeControlMidBrush}"
UseLayoutRounding="False">
<Grid RowDefinitions="Auto,*,Auto">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<RepeatButton Name="PART_LineUpButton"
Grid.Row="0"
MinHeight="{DynamicResource ScrollBarThickness}"
HorizontalAlignment="Center"
Classes="repeat"
Focusable="False">
<Path Data="M 0 4 L 8 4 L 4 0 Z" />
</RepeatButton>
<Track Grid.Row="1"
Grid.Column="1"
IsDirectionReversed="True"
Maximum="{TemplateBinding Maximum}"
Minimum="{TemplateBinding Minimum}"
Orientation="{TemplateBinding Orientation}"
ViewportSize="{TemplateBinding ViewportSize}"
DeferThumbDrag="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}"
Value="{TemplateBinding Value,
Mode=TwoWay}">
<Track.DecreaseButton>
<RepeatButton Name="PART_PageUpButton"
Classes="repeattrack"
Focusable="False" />
</Track.DecreaseButton>
<Track.IncreaseButton>
<RepeatButton Name="PART_PageDownButton"
Classes="repeattrack"
Focusable="False" />
</Track.IncreaseButton>
<Thumb Name="thumb" />
</Track>
<RepeatButton Name="PART_LineDownButton"
Grid.Row="2"
Grid.Column="2"
MinHeight="{DynamicResource ScrollBarThickness}"
HorizontalAlignment="Center"
Classes="repeat"
Focusable="False">
<Path Data="M 0 0 L 4 4 L 8 0 Z" />
</RepeatButton>
</Grid>
</Border>
</ControlTemplate>
</Setter>
</Style>
<Style Selector="^ /template/ Thumb#thumb">
<Setter Property="Background"
Value="{DynamicResource ThemeControlMidHighBrush}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Border Background="{TemplateBinding Background}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style Selector="^ /template/ Thumb#thumb:pointerover">
<Setter Property="Background"
Value="{DynamicResource ThemeControlHighBrush}" />
</Style>
<Style Selector="^ /template/ Thumb#thumb:pressed">
<Setter Property="Background"
Value="{DynamicResource ThemeControlVeryHighBrush}" />
</Style>
<Style Selector="^:horizontal /template/ Thumb#thumb">
<Setter Property="MinWidth"
Value="{DynamicResource ScrollBarThickness}" />
<Setter Property="Height"
Value="{DynamicResource ScrollBarThumbThickness}" />
</Style>
<Style Selector="^:vertical /template/ Thumb#thumb">
<Setter Property="MinHeight"
Value="{DynamicResource ScrollBarThickness}" />
<Setter Property="Width"
Value="{DynamicResource ScrollBarThumbThickness}" />
</Style>
<Style Selector="^ /template/ RepeatButton.repeat">
<Setter Property="Padding"
Value="2" />
<Setter Property="BorderThickness"
Value="0" />
</Style>
<Style Selector="^ /template/ RepeatButton.repeattrack">
<Setter Property="Template">
<ControlTemplate>
<Border Background="{TemplateBinding Background}" />
</ControlTemplate>
</Setter>
</Style>
<Style Selector="^ /template/ RepeatButton > Path">
<Setter Property="Fill"
Value="{DynamicResource ThemeForegroundLowBrush}" />
</Style>
<Style Selector="^ /template/ RepeatButton:pointerover > Path">
<Setter Property="Fill"
Value="{DynamicResource ThemeAccentBrush}" />
</Style>
</ControlTheme>
</ResourceDictionary>
@@ -1,5 +1,189 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ControlTheme x:Key="ScrollBarBaseRepeatButton"
TargetType="RepeatButton">
<Setter Property="Background"
Value="Transparent" />
<Setter Property="Focusable"
Value="false" />
<Setter Property="IsTabStop"
Value="false" />
<Setter Property="Template">
<ControlTemplate TargetType="RepeatButton">
<Rectangle Fill="{TemplateBinding Background}"
Height="{TemplateBinding Height}"
Width="{TemplateBinding Width}" />
</ControlTemplate>
</Setter>
</ControlTheme>
<ControlTheme x:Key="ScrollBarBaseThumbVertical"
TargetType="Thumb">
<Setter Property="Background"
Value="{DynamicResource SecondaryTextBrush}" />
<Setter Property="IsTabStop"
Value="false" />
<Setter Property="Template">
<ControlTemplate>
<Border Width="{TemplateBinding Width}"
Background="Transparent">
<Rectangle x:Name="rectangle"
RadiusX="1"
RadiusY="1"
HorizontalAlignment="Center"
Height="{TemplateBinding Height}"
Width="2"
Fill="{TemplateBinding Background}">
<Rectangle.Transitions>
<Transitions>
<DoubleTransition Property="Width"
Duration="0:0:0.1" />
<DoubleTransition Property="RadiusX"
Duration="0:0:0.1" />
<DoubleTransition Property="RadiusY"
Duration="0:0:0.1" />
</Transitions>
</Rectangle.Transitions>
</Rectangle>
</Border>
</ControlTemplate>
</Setter>
<Style Selector="^:pointerover /template/ Rectangle">
<Setter Property="Width"
Value="8" />
<Setter Property="RadiusX"
Value="4" />
<Setter Property="RadiusY"
Value="4" />
</Style>
<Style Selector="^:pressed /template/ Rectangle">
<Setter Property="Fill"
Value="{DynamicResource PrimaryTextBrush}" />
</Style>
</ControlTheme>
<ControlTheme x:Key="ScrollBarBaseThumbHorizontal"
TargetType="Thumb">
<Setter Property="Background"
Value="{DynamicResource SecondaryTextBrush}" />
<Setter Property="IsTabStop"
Value="false" />
<Setter Property="Template">
<ControlTemplate>
<Border Width="{TemplateBinding Height}"
Background="Transparent">
<Rectangle x:Name="rectangle"
RadiusX="1"
RadiusY="1"
VerticalAlignment="Center"
Height="2"
Width="{TemplateBinding Width}"
Fill="{TemplateBinding Background}">
<Rectangle.Transitions>
<Transitions>
<DoubleTransition Property="Height"
Duration="0:0:0.1" />
<DoubleTransition Property="RadiusX"
Duration="0:0:0.1" />
<DoubleTransition Property="RadiusY"
Duration="0:0:0.1" />
</Transitions>
</Rectangle.Transitions>
</Rectangle>
</Border>
</ControlTemplate>
</Setter>
<Style Selector="^:pointerover /template/ Rectangle">
<Setter Property="Height"
Value="8" />
<Setter Property="RadiusX"
Value="4" />
<Setter Property="RadiusY"
Value="4" />
</Style>
<Style Selector="^:pressed /template/ Rectangle">
<Setter Property="Fill"
Value="{DynamicResource PrimaryTextBrush}" />
</Style>
</ControlTheme>
<ControlTheme x:Key="ScrollBarBaseStyle"
TargetType="ScrollBar">
<Setter Property="Background"
Value="Transparent" />
<Setter Property="Focusable"
Value="False" />
<Setter Property="BorderThickness"
Value="0" />
<Setter Property="MinHeight"
Value="8" />
<Setter Property="MinWidth"
Value="8" />
<Setter Property="Transitions">
<Transitions>
<DoubleTransition Property="Opacity"
Duration="0:0:0.1" />
</Transitions>
</Setter>
<Style Selector="^:horizontal">
<Setter Property="Template">
<ControlTemplate>
<Panel>
<Border Background="{TemplateBinding Background}" />
<Track Maximum="{TemplateBinding Maximum}"
Minimum="{TemplateBinding Minimum}"
Orientation="{TemplateBinding Orientation}"
ViewportSize="{TemplateBinding ViewportSize}"
DeferThumbDrag="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}"
Value="{TemplateBinding Value, Mode=TwoWay}">
<Track.DecreaseButton>
<RepeatButton Name="PART_PageUpButton"
Theme="{StaticResource ScrollBarBaseRepeatButton}" />
</Track.DecreaseButton>
<Track.IncreaseButton>
<RepeatButton Name="PART_PageDownButton"
Theme="{StaticResource ScrollBarBaseRepeatButton}" />
</Track.IncreaseButton>
<Thumb Theme="{StaticResource ScrollBarBaseThumbHorizontal}" />
</Track>
</Panel>
</ControlTemplate>
</Setter>
</Style>
<Style Selector="^:vertical">
<Setter Property="Template">
<ControlTemplate>
<Panel>
<Border Background="{TemplateBinding Background}" />
<Track IsDirectionReversed="True"
Maximum="{TemplateBinding Maximum}"
Minimum="{TemplateBinding Minimum}"
Orientation="{TemplateBinding Orientation}"
ViewportSize="{TemplateBinding ViewportSize}"
DeferThumbDrag="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}"
Value="{TemplateBinding Value, Mode=TwoWay}">
<Track.DecreaseButton>
<RepeatButton Name="PART_PageUpButton"
Theme="{StaticResource ScrollBarBaseRepeatButton}" />
</Track.DecreaseButton>
<Track.IncreaseButton>
<RepeatButton Name="PART_PageDownButton"
Theme="{StaticResource ScrollBarBaseRepeatButton}" />
</Track.IncreaseButton>
<Thumb Theme="{StaticResource ScrollBarBaseThumbVertical}" />
</Track>
</Panel>
</ControlTemplate>
</Setter>
</Style>
</ControlTheme>
<ControlTheme x:Key="{x:Type ScrollViewer}"
TargetType="ScrollViewer">
<Setter Property="Background"
@@ -9,6 +193,8 @@
<Grid ColumnDefinitions="*,Auto"
RowDefinitions="*,Auto">
<ScrollContentPresenter Name="PART_ContentPresenter"
Grid.RowSpan="2"
Grid.ColumnSpan="2"
Padding="{TemplateBinding Padding}"
HorizontalSnapPointsType="{TemplateBinding HorizontalSnapPointsType}"
VerticalSnapPointsType="{TemplateBinding VerticalSnapPointsType}"
@@ -25,16 +211,22 @@
<ScrollBar Name="PART_HorizontalScrollBar"
Grid.Row="1"
Grid.Column="0"
Opacity=".3"
Theme="{StaticResource ScrollBarBaseStyle}"
Orientation="Horizontal" />
<ScrollBar Name="PART_VerticalScrollBar"
Grid.Row="0"
Grid.Column="1"
Opacity="0"
Theme="{StaticResource ScrollBarBaseStyle}"
Orientation="Vertical" />
<Panel Grid.Row="1"
Grid.Column="1"
Background="{DynamicResource ThemeControlMidBrush}" />
</Grid>
</ControlTemplate>
</Setter>
<Style Selector="^:pointerover /template/ ScrollBar">
<Setter Property="Opacity"
Value=".8" />
</Style>
</ControlTheme>
</ResourceDictionary>
@@ -9,14 +9,14 @@
<MergeResourceInclude Source="avares://HandyControl/Themes/Styles/UserControl.axaml" />
<MergeResourceInclude Source="avares://HandyControl/Themes/Styles/Window.axaml" />
<MergeResourceInclude Source="avares://HandyControl/Themes/Styles/Button.axaml" />
<MergeResourceInclude Source="avares://HandyControl/Themes/Styles/RepeatButton.axaml" />
<MergeResourceInclude Source="avares://HandyControl/Themes/Styles/Border.axaml" />
<MergeResourceInclude Source="avares://HandyControl/Themes/Styles/ItemsControl.axaml" />
<MergeResourceInclude Source="avares://HandyControl/Themes/Styles/TabItem.axaml" />
<MergeResourceInclude Source="avares://HandyControl/Themes/Styles/TabControl.axaml" />
<MergeResourceInclude Source="avares://HandyControl/Themes/Styles/ListBoxItem.axaml" />
<MergeResourceInclude Source="avares://HandyControl/Themes/Styles/ListBox.axaml" />
<MergeResourceInclude Source="avares://HandyControl/Themes/Styles/ScrollBar.axaml" />
<MergeResourceInclude Source="avares://HandyControl/Themes/Styles/ScrollViewer.axaml" />
<MergeResourceInclude Source="avares://HandyControl/Themes/Styles/ListBox.axaml" />
<MergeResourceInclude Source="avares://HandyControl/Themes/Styles/Label.axaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>