fix: fix popup Padding.

This commit is contained in:
Zhang Dian 2024-12-01 23:34:26 +08:00
parent 266fdade35
commit 50b5159d17
7 changed files with 92 additions and 105 deletions

View File

@ -33,22 +33,19 @@
PlacementTarget="{TemplateBinding}"> PlacementTarget="{TemplateBinding}">
<Border <Border
Margin="{DynamicResource AutoCompleteBoxPopupMargin}" Margin="{DynamicResource AutoCompleteBoxPopupMargin}"
Padding="{DynamicResource AutoCompleteBoxPopupPadding}"
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
Background="{DynamicResource AutoCompleteBoxPopupBackground}" Background="{DynamicResource AutoCompleteBoxPopupBackground}"
BorderBrush="{DynamicResource AutoCompleteBoxPopupBorderBrush}" BorderBrush="{DynamicResource AutoCompleteBoxPopupBorderBrush}"
BorderThickness="{DynamicResource AutoCompleteBoxPopupBorderThickness}" BorderThickness="{DynamicResource AutoCompleteBoxPopupBorderThickness}"
BoxShadow="{DynamicResource AutoCompleteBoxPopupBoxShadow}" BoxShadow="{DynamicResource AutoCompleteBoxPopupBoxShadow}"
CornerRadius="{DynamicResource AutoCompleteBoxPopupCornerRadius}"> CornerRadius="{DynamicResource AutoCompleteBoxPopupCornerRadius}">
<Border <ListBox
CornerRadius="{DynamicResource AutoCompleteBoxPopupCornerRadius}" Name="PART_SelectingItemsControl"
ClipToBounds="True"> Foreground="{TemplateBinding Foreground}"
<ListBox ItemTemplate="{TemplateBinding ItemTemplate}"
Name="PART_SelectingItemsControl" ScrollViewer.HorizontalScrollBarVisibility="Auto"
Foreground="{TemplateBinding Foreground}" ScrollViewer.VerticalScrollBarVisibility="Auto" />
ItemTemplate="{TemplateBinding ItemTemplate}"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Auto" />
</Border>
</Border> </Border>
</Popup> </Popup>
</Panel> </Panel>
@ -75,22 +72,19 @@
PlacementTarget="{TemplateBinding}"> PlacementTarget="{TemplateBinding}">
<Border <Border
Margin="{DynamicResource AutoCompleteBoxPopupMargin}" Margin="{DynamicResource AutoCompleteBoxPopupMargin}"
Padding="{DynamicResource AutoCompleteBoxPopupPadding}"
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
Background="{DynamicResource AutoCompleteBoxPopupBackground}" Background="{DynamicResource AutoCompleteBoxPopupBackground}"
BorderBrush="{DynamicResource AutoCompleteBoxPopupBorderBrush}" BorderBrush="{DynamicResource AutoCompleteBoxPopupBorderBrush}"
BorderThickness="{DynamicResource AutoCompleteBoxPopupBorderThickness}" BorderThickness="{DynamicResource AutoCompleteBoxPopupBorderThickness}"
BoxShadow="{DynamicResource AutoCompleteBoxPopupBoxShadow}" BoxShadow="{DynamicResource AutoCompleteBoxPopupBoxShadow}"
CornerRadius="{DynamicResource AutoCompleteBoxPopupCornerRadius}"> CornerRadius="{DynamicResource AutoCompleteBoxPopupCornerRadius}">
<Border
CornerRadius="{DynamicResource AutoCompleteBoxPopupCornerRadius}"
ClipToBounds="True">
<ListBox <ListBox
Name="PART_SelectingItemsControl" Name="PART_SelectingItemsControl"
Foreground="{TemplateBinding Foreground}" Foreground="{TemplateBinding Foreground}"
ItemTemplate="{TemplateBinding ItemTemplate}" ItemTemplate="{TemplateBinding ItemTemplate}"
ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Auto" /> ScrollViewer.VerticalScrollBarVisibility="Auto" />
</Border>
</Border> </Border>
</Popup> </Popup>
</Panel> </Panel>

View File

@ -102,7 +102,6 @@
Grid.Column="0" Grid.Column="0"
MinWidth="{Binding Bounds.Width, RelativeSource={RelativeSource TemplatedParent}}" MinWidth="{Binding Bounds.Width, RelativeSource={RelativeSource TemplatedParent}}"
MaxHeight="{TemplateBinding MaxDropDownHeight}" MaxHeight="{TemplateBinding MaxDropDownHeight}"
ClipToBounds="False"
InheritsTransform="True" InheritsTransform="True"
IsLightDismissEnabled="True" IsLightDismissEnabled="True"
IsOpen="{TemplateBinding IsDropDownOpen, Mode=TwoWay}" IsOpen="{TemplateBinding IsDropDownOpen, Mode=TwoWay}"
@ -112,23 +111,20 @@
Name="PopupBorder" Name="PopupBorder"
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
Margin="{DynamicResource ComboBoxPopupBorderMargin}" Margin="{DynamicResource ComboBoxPopupBorderMargin}"
Padding="{DynamicResource ComboBoxPopupBorderPadding}"
Background="{DynamicResource ComboBoxPopupBackground}" Background="{DynamicResource ComboBoxPopupBackground}"
BorderBrush="{DynamicResource ComboBoxPopupBorderBrush}" BorderBrush="{DynamicResource ComboBoxPopupBorderBrush}"
BorderThickness="{DynamicResource ComboBoxPopupBorderThickness}" BorderThickness="{DynamicResource ComboBoxPopupBorderThickness}"
BoxShadow="{DynamicResource ComboBoxPopupBoxShadow}" BoxShadow="{DynamicResource ComboBoxPopupBoxShadow}"
CornerRadius="{DynamicResource ComboBoxPopupBoxCornerRadius}"> CornerRadius="{DynamicResource ComboBoxPopupBoxCornerRadius}">
<Border <ScrollViewer
CornerRadius="{DynamicResource ComboBoxPopupBoxCornerRadius}" HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
ClipToBounds="True"> IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}"
<ScrollViewer VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}">
HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}" <ItemsPresenter
IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}" Name="PART_ItemsPresenter"
VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"> ItemsPanel="{TemplateBinding ItemsPanel}" />
<ItemsPresenter </ScrollViewer>
Name="PART_ItemsPresenter"
ItemsPanel="{TemplateBinding ItemsPanel}" />
</ScrollViewer>
</Border>
</Border> </Border>
</Popup> </Popup>
</Grid> </Grid>

View File

@ -10,81 +10,77 @@
<Setter Property="Background" Value="Transparent" /> <Setter Property="Background" Value="Transparent" />
<Setter Property="Template"> <Setter Property="Template">
<ControlTemplate TargetType="ScrollViewer"> <ControlTemplate TargetType="ScrollViewer">
<Border <DockPanel>
ClipToBounds="True" <DockPanel.Styles>
CornerRadius="{TemplateBinding CornerRadius}"> <Style Selector="RepeatButton:pressed">
<DockPanel> <Setter Property="RenderTransform" Value="{x:Null}" />
<DockPanel.Styles> </Style>
<Style Selector="RepeatButton:pressed"> </DockPanel.Styles>
<Setter Property="RenderTransform" Value="{x:Null}" /> <RepeatButton
</Style> HorizontalAlignment="Stretch"
</DockPanel.Styles> HorizontalContentAlignment="Center"
<RepeatButton Background="Transparent"
HorizontalAlignment="Stretch" BorderThickness="0"
HorizontalContentAlignment="Center" Command="{Binding LineUp, RelativeSource={RelativeSource TemplatedParent}}"
Background="Transparent" CornerRadius="0"
BorderThickness="0" DockPanel.Dock="Top"
Command="{Binding LineUp, RelativeSource={RelativeSource TemplatedParent}}" RenderTransform="{x:Null}">
CornerRadius="0" <RepeatButton.IsVisible>
DockPanel.Dock="Top" <MultiBinding
RenderTransform="{x:Null}"> Converter="{x:Static converters:MenuScrollingVisibilityConverter.Instance}"
<RepeatButton.IsVisible> ConverterParameter="0">
<MultiBinding <Binding Path="VerticalScrollBarVisibility"
Converter="{x:Static converters:MenuScrollingVisibilityConverter.Instance}" RelativeSource="{RelativeSource TemplatedParent}" />
ConverterParameter="0"> <Binding Path="Offset.Y" RelativeSource="{RelativeSource TemplatedParent}" />
<Binding Path="VerticalScrollBarVisibility" <Binding Path="Extent.Height" RelativeSource="{RelativeSource TemplatedParent}" />
RelativeSource="{RelativeSource TemplatedParent}" /> <Binding Path="Viewport.Height" RelativeSource="{RelativeSource TemplatedParent}" />
<Binding Path="Offset.Y" RelativeSource="{RelativeSource TemplatedParent}" /> </MultiBinding>
<Binding Path="Extent.Height" RelativeSource="{RelativeSource TemplatedParent}" /> </RepeatButton.IsVisible>
<Binding Path="Viewport.Height" RelativeSource="{RelativeSource TemplatedParent}" /> <PathIcon
</MultiBinding> Theme="{DynamicResource InnerPathIcon}"
</RepeatButton.IsVisible> Data="{DynamicResource MenuScrollViewerUpButtonGlyph}"
<PathIcon Foreground="{DynamicResource MenuFlyoutScrollViewerIconForeground}" />
Theme="{DynamicResource InnerPathIcon}" </RepeatButton>
Data="{DynamicResource MenuScrollViewerUpButtonGlyph}" <RepeatButton
Foreground="{DynamicResource MenuFlyoutScrollViewerIconForeground}" /> HorizontalAlignment="Stretch"
</RepeatButton> HorizontalContentAlignment="Center"
<RepeatButton Background="Transparent"
HorizontalAlignment="Stretch" BorderThickness="0"
HorizontalContentAlignment="Center" Command="{Binding LineDown, RelativeSource={RelativeSource TemplatedParent}}"
Background="Transparent" CornerRadius="0"
BorderThickness="0" DockPanel.Dock="Bottom"
Command="{Binding LineDown, RelativeSource={RelativeSource TemplatedParent}}" RenderTransform="{x:Null}">
CornerRadius="0" <RepeatButton.IsVisible>
DockPanel.Dock="Bottom" <MultiBinding
RenderTransform="{x:Null}"> Converter="{x:Static converters:MenuScrollingVisibilityConverter.Instance}"
<RepeatButton.IsVisible> ConverterParameter="100">
<MultiBinding <Binding Path="VerticalScrollBarVisibility"
Converter="{x:Static converters:MenuScrollingVisibilityConverter.Instance}" RelativeSource="{RelativeSource TemplatedParent}" />
ConverterParameter="100"> <Binding Path="Offset.Y" RelativeSource="{RelativeSource TemplatedParent}" />
<Binding Path="VerticalScrollBarVisibility" <Binding Path="Extent.Height" RelativeSource="{RelativeSource TemplatedParent}" />
RelativeSource="{RelativeSource TemplatedParent}" /> <Binding Path="Viewport.Height" RelativeSource="{RelativeSource TemplatedParent}" />
<Binding Path="Offset.Y" RelativeSource="{RelativeSource TemplatedParent}" /> </MultiBinding>
<Binding Path="Extent.Height" RelativeSource="{RelativeSource TemplatedParent}" /> </RepeatButton.IsVisible>
<Binding Path="Viewport.Height" RelativeSource="{RelativeSource TemplatedParent}" /> <PathIcon
</MultiBinding> Theme="{DynamicResource InnerPathIcon}"
</RepeatButton.IsVisible> Data="{DynamicResource MenuScrollViewerDownButtonGlyph}"
<PathIcon Foreground="{DynamicResource MenuFlyoutScrollViewerIconForeground}" />
Theme="{DynamicResource InnerPathIcon}" </RepeatButton>
Data="{DynamicResource MenuScrollViewerDownButtonGlyph}" <ScrollContentPresenter
Foreground="{DynamicResource MenuFlyoutScrollViewerIconForeground}" /> Name="PART_ContentPresenter"
</RepeatButton> Margin="{TemplateBinding Padding}"
<ScrollContentPresenter HorizontalSnapPointsAlignment="{TemplateBinding HorizontalSnapPointsAlignment}"
Name="PART_ContentPresenter" HorizontalSnapPointsType="{TemplateBinding HorizontalSnapPointsType}"
Margin="{TemplateBinding Padding}" VerticalSnapPointsAlignment="{TemplateBinding VerticalSnapPointsAlignment}"
HorizontalSnapPointsAlignment="{TemplateBinding HorizontalSnapPointsAlignment}" VerticalSnapPointsType="{TemplateBinding VerticalSnapPointsType}">
HorizontalSnapPointsType="{TemplateBinding HorizontalSnapPointsType}" <ScrollContentPresenter.GestureRecognizers>
VerticalSnapPointsAlignment="{TemplateBinding VerticalSnapPointsAlignment}" <ScrollGestureRecognizer
VerticalSnapPointsType="{TemplateBinding VerticalSnapPointsType}"> CanHorizontallyScroll="{Binding CanHorizontallyScroll, ElementName=PART_ContentPresenter}"
<ScrollContentPresenter.GestureRecognizers> CanVerticallyScroll="{Binding CanVerticallyScroll, ElementName=PART_ContentPresenter}"
<ScrollGestureRecognizer IsScrollInertiaEnabled="{Binding IsScrollInertiaEnabled, RelativeSource={RelativeSource TemplatedParent}}" />
CanHorizontallyScroll="{Binding CanHorizontallyScroll, ElementName=PART_ContentPresenter}" </ScrollContentPresenter.GestureRecognizers>
CanVerticallyScroll="{Binding CanVerticallyScroll, ElementName=PART_ContentPresenter}" </ScrollContentPresenter>
IsScrollInertiaEnabled="{Binding IsScrollInertiaEnabled, RelativeSource={RelativeSource TemplatedParent}}" /> </DockPanel>
</ScrollContentPresenter.GestureRecognizers>
</ScrollContentPresenter>
</DockPanel>
</Border>
</ControlTemplate> </ControlTemplate>
</Setter> </Setter>
</ControlTheme> </ControlTheme>
@ -113,7 +109,6 @@
<ControlTheme x:Key="{x:Type MenuItem}" TargetType="MenuItem"> <ControlTheme x:Key="{x:Type MenuItem}" TargetType="MenuItem">
<Setter Property="Background" Value="{DynamicResource MenuItemBackground}" /> <Setter Property="Background" Value="{DynamicResource MenuItemBackground}" />
<Setter Property="Foreground" Value="{DynamicResource MenuItemForeground}" /> <Setter Property="Foreground" Value="{DynamicResource MenuItemForeground}" />
<Setter Property="CornerRadius" Value="{DynamicResource MenuItemCornerRadius}" />
<Setter Property="Cursor" Value="Hand" /> <Setter Property="Cursor" Value="Hand" />
<!-- Narrow padding should be used for mouse input, when non-narrow one should be used for touch input in future. --> <!-- Narrow padding should be used for mouse input, when non-narrow one should be used for touch input in future. -->
<Setter Property="Padding" Value="{DynamicResource MenuItemPadding}" /> <Setter Property="Padding" Value="{DynamicResource MenuItemPadding}" />

View File

@ -1,6 +1,7 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Thickness x:Key="AutoCompleteBoxPopupBorderThickness">1</Thickness> <Thickness x:Key="AutoCompleteBoxPopupBorderThickness">1</Thickness>
<Thickness x:Key="AutoCompleteBoxPopupMargin">4</Thickness> <Thickness x:Key="AutoCompleteBoxPopupMargin">4</Thickness>
<Thickness x:Key="AutoCompleteBoxPopupPadding">0 4</Thickness>
<CornerRadius x:Key="AutoCompleteBoxPopupCornerRadius">6</CornerRadius> <CornerRadius x:Key="AutoCompleteBoxPopupCornerRadius">6</CornerRadius>
<x:Double x:Key="AutoCompleteBoxDefaultHeight">32</x:Double> <x:Double x:Key="AutoCompleteBoxDefaultHeight">32</x:Double>
<x:Double x:Key="AutoCompleteBoxSmallHeight">24</x:Double> <x:Double x:Key="AutoCompleteBoxSmallHeight">24</x:Double>

View File

@ -14,6 +14,7 @@
M4.08045 7.59809C4.66624 7.01231 5.61599 7.01231 6.20177 7.59809L11.8586 13.2549L17.5155 7.59809C18.1013 7.01231 19.051 7.01231 19.6368 7.59809C20.2226 8.18388 20.2226 9.13363 19.6368 9.71941L12.9193 16.4369C12.3335 17.0227 11.3838 17.0227 10.798 16.4369L4.08045 9.71941C3.49467 9.13363 3.49467 8.18388 4.08045 7.59809Z M4.08045 7.59809C4.66624 7.01231 5.61599 7.01231 6.20177 7.59809L11.8586 13.2549L17.5155 7.59809C18.1013 7.01231 19.051 7.01231 19.6368 7.59809C20.2226 8.18388 20.2226 9.13363 19.6368 9.71941L12.9193 16.4369C12.3335 17.0227 11.3838 17.0227 10.798 16.4369L4.08045 9.71941C3.49467 9.13363 3.49467 8.18388 4.08045 7.59809Z
</StreamGeometry> </StreamGeometry>
<Thickness x:Key="ComboBoxPopupBorderMargin">4</Thickness> <Thickness x:Key="ComboBoxPopupBorderMargin">4</Thickness>
<Thickness x:Key="ComboBoxPopupBorderPadding">0 4</Thickness>
<x:Double x:Key="ComboBoxDefaultHeight">32</x:Double> <x:Double x:Key="ComboBoxDefaultHeight">32</x:Double>
<x:Double x:Key="ComboBoxSmallHeight">24</x:Double> <x:Double x:Key="ComboBoxSmallHeight">24</x:Double>

View File

@ -1,6 +1,6 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<!-- ListBox --> <!-- ListBox -->
<Thickness x:Key="ListBoxItemDefaultPadding">12 8</Thickness> <Thickness x:Key="ListBoxItemDefaultPadding">12 8</Thickness>
<CornerRadius x:Key="ListBoxItemCornerRadius">3</CornerRadius> <CornerRadius x:Key="ListBoxItemCornerRadius">0</CornerRadius>
</ResourceDictionary> </ResourceDictionary>

View File

@ -6,7 +6,7 @@
<!-- MenuFlyout --> <!-- MenuFlyout -->
<Thickness x:Key="MenuFlyoutBorderThickness">1</Thickness> <Thickness x:Key="MenuFlyoutBorderThickness">1</Thickness>
<Thickness x:Key="MenuFlyoutPadding">0</Thickness> <Thickness x:Key="MenuFlyoutPadding">0 4</Thickness>
<CornerRadius x:Key="MenuFlyoutCornerRadius">6</CornerRadius> <CornerRadius x:Key="MenuFlyoutCornerRadius">6</CornerRadius>
<x:Double x:Key="MenuFlyoutMinHeight">16</x:Double> <x:Double x:Key="MenuFlyoutMinHeight">16</x:Double>
<x:Double x:Key="MenuFlyoutMinWidth">100</x:Double> <x:Double x:Key="MenuFlyoutMinWidth">100</x:Double>