Merge pull request #565 from irihitech/scroll

ScrollBar Update
This commit is contained in:
Zhang Dian
2025-03-14 16:39:01 +08:00
committed by GitHub
4 changed files with 27 additions and 64 deletions

View File

@@ -3,7 +3,6 @@
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:Semi.Avalonia.Demo.Pages"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:Semi.Avalonia.Demo.ViewModels;assembly=Semi.Avalonia.Demo"
d:DesignHeight="450"
@@ -15,8 +14,9 @@
<TabItem Header="DataGrid">
<Grid RowDefinitions="Auto, *">
<StackPanel Grid.Row="0" Orientation="Horizontal">
<ToggleSwitch Content="Disable" Name="DisableToggle" />
<ToggleSwitch Content="ScrollViewerHide" Name="ScrollViewerHide" />
<ToggleSwitch Content="Enable" Name="enable" IsChecked="True" />
<ToggleSwitch Content="Inset Content" Name="inset" />
<ToggleSwitch Content="ScrollBar Auto Hide" Name="autohide" />
</StackPanel>
<DataGrid Grid.Row="1"
Margin="8"
@@ -25,8 +25,9 @@
CanUserSortColumns="True"
HeadersVisibility="All"
IsReadOnly="True"
ScrollViewer.AllowAutoHide="{Binding #ScrollViewerHide.IsChecked}"
IsEnabled="{Binding #DisableToggle.IsChecked}"
Classes.InsetContent="{Binding #inset.IsChecked}"
ScrollViewer.AllowAutoHide="{Binding #autohide.IsChecked}"
IsEnabled="{Binding #enable.IsChecked}"
ItemsSource="{Binding GridData1}">
<DataGrid.Columns>
<DataGridTextColumn

View File

@@ -9,66 +9,22 @@
mc:Ignorable="d">
<ScrollViewer>
<StackPanel HorizontalAlignment="Left" Spacing="20">
<ToggleSwitch Name="inset" Content="Inset Content" />
<ToggleSwitch Name="autohide" Content="Allow AutoHide" />
<ScrollViewer
Width="200"
Height="200"
Margin="10"
Width="200" Height="200"
AllowAutoHide="{Binding #autohide.IsChecked}"
Classes.InsetContent="{Binding #inset.IsChecked}"
HorizontalScrollBarVisibility="Auto">
<Grid RowDefinitions="Auto,Auto"
ColumnDefinitions="Auto,Auto"
<UniformGrid
Rows="2" Columns="2"
Width="300" Height="300">
<Rectangle
Grid.Row="0" Grid.Column="0"
Width="150"
Height="150"
Fill="{DynamicResource SemiYellow2}" />
<Rectangle
Grid.Row="0" Grid.Column="1"
Width="150"
Height="150"
Fill="{DynamicResource SemiBlue2}" />
<Rectangle
Grid.Row="1" Grid.Column="0"
Width="150"
Height="150"
Fill="{DynamicResource SemiPink2}" />
<Rectangle
Grid.Row="1" Grid.Column="1"
Width="150"
Height="150"
Fill="{DynamicResource SemiGreen2}" />
</Grid>
</ScrollViewer>
<ScrollViewer
Width="200"
Height="200"
Margin="10"
HorizontalScrollBarVisibility="Auto"
Theme="{DynamicResource StaticScrollViewer}">
<Grid RowDefinitions="Auto,Auto"
ColumnDefinitions="Auto,Auto"
Width="300" Height="300">
<Rectangle
Grid.Row="0" Grid.Column="0"
Width="150"
Height="150"
Fill="{DynamicResource SemiYellow2}" />
<Rectangle
Grid.Row="0" Grid.Column="1"
Width="150"
Height="150"
Fill="{DynamicResource SemiBlue2}" />
<Rectangle
Grid.Row="1" Grid.Column="0"
Width="150"
Height="150"
Fill="{DynamicResource SemiPink2}" />
<Rectangle
Grid.Row="1" Grid.Column="1"
Width="150"
Height="150"
Fill="{DynamicResource SemiGreen2}" />
</Grid>
<Rectangle Fill="{DynamicResource SemiYellow2}" />
<Rectangle Fill="{DynamicResource SemiBlue2}" />
<Rectangle Fill="{DynamicResource SemiPink2}" />
<Rectangle Fill="{DynamicResource SemiGreen2}" />
</UniformGrid>
</ScrollViewer>
</StackPanel>
</ScrollViewer>

View File

@@ -530,6 +530,7 @@
Name="PART_VerticalScrollbar"
Grid.Row="1"
Grid.Column="2"
AllowAutoHide="{Binding Path=(ScrollViewer.AllowAutoHide), RelativeSource={RelativeSource TemplatedParent}}"
Orientation="Vertical" />
<Grid
@@ -540,6 +541,7 @@
<ScrollBar
Name="PART_HorizontalScrollbar"
Grid.Column="1"
AllowAutoHide="{Binding Path=(ScrollViewer.AllowAutoHide), RelativeSource={RelativeSource TemplatedParent}}"
Height="{DynamicResource ScrollBarSize}"
Orientation="Horizontal" />
</Grid>
@@ -572,7 +574,7 @@
</Style>
</Style>
<Style Selector="^[(ScrollViewer.AllowAutoHide)=False]">
<Style Selector="^.InsetContent">
<Style Selector="^ /template/ DataGridRowsPresenter#PART_RowsPresenter">
<Setter Property="Grid.RowSpan" Value="1" />
<Setter Property="Grid.ColumnSpan" Value="2" />

View File

@@ -229,7 +229,6 @@
<Setter Property="Height" Value="2" />
</Style>
</Style>
</ControlTheme>
<ControlTheme x:Key="{x:Type ScrollViewer}" TargetType="ScrollViewer">
<Setter Property="Background" Value="Transparent" />
@@ -278,9 +277,14 @@
<Setter Property="Opacity" Value="1" />
</Style>
</Style>
<Style Selector="^.InsetContent /template/ ScrollContentPresenter#PART_ContentPresenter">
<Setter Property="Grid.RowSpan" Value="1"/>
<Setter Property="Grid.ColumnSpan" Value="1"/>
</Style>
</ControlTheme>
<ControlTheme x:Key="StaticScrollViewer" TargetType="ScrollViewer">
<!-- This ControlTheme equivalent to default ScrollViewer with InsetContent style class. It exists for easier setting via style. -->
<Setter Property="Background" Value="Transparent" />
<Setter Property="Template">
<ControlTemplate TargetType="ScrollViewer">