fix: remove MenuFlyoutPadding.

(cherry picked from commit 4bd73119acf46137eda3b088686f32cafb2ac97b)
This commit is contained in:
Zhang Dian 2024-08-30 16:00:58 +08:00
parent 33e4510097
commit c725362d16
3 changed files with 96 additions and 71 deletions

View File

@ -10,73 +10,83 @@
<Setter Property="Background" Value="Transparent" /> <Setter Property="Background" Value="Transparent" />
<Setter Property="Template"> <Setter Property="Template">
<ControlTemplate TargetType="ScrollViewer"> <ControlTemplate TargetType="ScrollViewer">
<DockPanel> <Border
<DockPanel.Styles> ClipToBounds="True"
<Style Selector="RepeatButton:pressed"> CornerRadius="{TemplateBinding CornerRadius}">
<Setter Property="RenderTransform" Value="{x:Null}" /> <DockPanel>
</Style> <DockPanel.Styles>
</DockPanel.Styles> <Style Selector="RepeatButton:pressed">
<RepeatButton <Setter Property="RenderTransform" Value="{x:Null}" />
HorizontalAlignment="Stretch" </Style>
HorizontalContentAlignment="Center" </DockPanel.Styles>
Background="Transparent" <RepeatButton
BorderThickness="0" HorizontalAlignment="Stretch"
Command="{Binding LineUp, RelativeSource={RelativeSource TemplatedParent}}" HorizontalContentAlignment="Center"
CornerRadius="0" Background="Transparent"
DockPanel.Dock="Top" BorderThickness="0"
RenderTransform="{x:Null}"> Command="{Binding LineUp, RelativeSource={RelativeSource TemplatedParent}}"
<RepeatButton.IsVisible> CornerRadius="0"
<MultiBinding Converter="{x:Static converters:MenuScrollingVisibilityConverter.Instance}" ConverterParameter="0"> DockPanel.Dock="Top"
<ReflectionBinding Path="VerticalScrollBarVisibility" RelativeSource="{RelativeSource TemplatedParent}" /> RenderTransform="{x:Null}">
<ReflectionBinding Path="Offset.Y" RelativeSource="{RelativeSource TemplatedParent}" /> <RepeatButton.IsVisible>
<ReflectionBinding Path="Extent.Height" RelativeSource="{RelativeSource TemplatedParent}" /> <MultiBinding
<ReflectionBinding Path="Viewport.Height" RelativeSource="{RelativeSource TemplatedParent}" /> Converter="{x:Static converters:MenuScrollingVisibilityConverter.Instance}"
</MultiBinding> ConverterParameter="0">
</RepeatButton.IsVisible> <Binding Path="VerticalScrollBarVisibility"
<PathIcon RelativeSource="{RelativeSource TemplatedParent}" />
Width="8" <Binding Path="Offset.Y" RelativeSource="{RelativeSource TemplatedParent}" />
Height="8" <Binding Path="Extent.Height" RelativeSource="{RelativeSource TemplatedParent}" />
Data="{DynamicResource MenuScrollViewerUpButtonGlyph}" <Binding Path="Viewport.Height" RelativeSource="{RelativeSource TemplatedParent}" />
Foreground="{DynamicResource MenuFlyoutScrollViewerIconForeground}" /> </MultiBinding>
</RepeatButton> </RepeatButton.IsVisible>
<RepeatButton <PathIcon
HorizontalAlignment="Stretch" Width="8"
HorizontalContentAlignment="Center" Height="8"
Background="Transparent" Data="{DynamicResource MenuScrollViewerUpButtonGlyph}"
BorderThickness="0" Foreground="{DynamicResource MenuFlyoutScrollViewerIconForeground}" />
Command="{Binding LineDown, RelativeSource={RelativeSource TemplatedParent}}" </RepeatButton>
CornerRadius="0" <RepeatButton
DockPanel.Dock="Bottom" HorizontalAlignment="Stretch"
RenderTransform="{x:Null}"> HorizontalContentAlignment="Center"
<RepeatButton.IsVisible> Background="Transparent"
<MultiBinding Converter="{x:Static converters:MenuScrollingVisibilityConverter.Instance}" ConverterParameter="100"> BorderThickness="0"
<ReflectionBinding Path="VerticalScrollBarVisibility" RelativeSource="{RelativeSource TemplatedParent}" /> Command="{Binding LineDown, RelativeSource={RelativeSource TemplatedParent}}"
<ReflectionBinding Path="Offset.Y" RelativeSource="{RelativeSource TemplatedParent}" /> CornerRadius="0"
<ReflectionBinding Path="Extent.Height" RelativeSource="{RelativeSource TemplatedParent}" /> DockPanel.Dock="Bottom"
<ReflectionBinding Path="Viewport.Height" RelativeSource="{RelativeSource TemplatedParent}" /> RenderTransform="{x:Null}">
</MultiBinding> <RepeatButton.IsVisible>
</RepeatButton.IsVisible> <MultiBinding
<PathIcon Converter="{x:Static converters:MenuScrollingVisibilityConverter.Instance}"
Width="8" ConverterParameter="100">
Height="8" <Binding Path="VerticalScrollBarVisibility"
Data="{DynamicResource MenuScrollViewerDownButtonGlyph}" RelativeSource="{RelativeSource TemplatedParent}" />
Foreground="{DynamicResource MenuFlyoutScrollViewerIconForeground}" /> <Binding Path="Offset.Y" RelativeSource="{RelativeSource TemplatedParent}" />
</RepeatButton> <Binding Path="Extent.Height" RelativeSource="{RelativeSource TemplatedParent}" />
<ScrollContentPresenter <Binding Path="Viewport.Height" RelativeSource="{RelativeSource TemplatedParent}" />
Name="PART_ContentPresenter" </MultiBinding>
Margin="{TemplateBinding Padding}" </RepeatButton.IsVisible>
HorizontalSnapPointsAlignment="{TemplateBinding HorizontalSnapPointsAlignment}" <PathIcon
HorizontalSnapPointsType="{TemplateBinding HorizontalSnapPointsType}" Width="8"
VerticalSnapPointsAlignment="{TemplateBinding VerticalSnapPointsAlignment}" Height="8"
VerticalSnapPointsType="{TemplateBinding VerticalSnapPointsType}"> Data="{DynamicResource MenuScrollViewerDownButtonGlyph}"
<ScrollContentPresenter.GestureRecognizers> Foreground="{DynamicResource MenuFlyoutScrollViewerIconForeground}" />
<ScrollGestureRecognizer </RepeatButton>
CanHorizontallyScroll="{Binding CanHorizontallyScroll, ElementName=PART_ContentPresenter}" <ScrollContentPresenter
CanVerticallyScroll="{Binding CanVerticallyScroll, ElementName=PART_ContentPresenter}" Name="PART_ContentPresenter"
IsScrollInertiaEnabled="{Binding IsScrollInertiaEnabled, RelativeSource={RelativeSource TemplatedParent}}" /> Margin="{TemplateBinding Padding}"
</ScrollContentPresenter.GestureRecognizers> HorizontalSnapPointsAlignment="{TemplateBinding HorizontalSnapPointsAlignment}"
</ScrollContentPresenter> HorizontalSnapPointsType="{TemplateBinding HorizontalSnapPointsType}"
</DockPanel> VerticalSnapPointsAlignment="{TemplateBinding VerticalSnapPointsAlignment}"
VerticalSnapPointsType="{TemplateBinding VerticalSnapPointsType}">
<ScrollContentPresenter.GestureRecognizers>
<ScrollGestureRecognizer
CanHorizontallyScroll="{Binding CanHorizontallyScroll, ElementName=PART_ContentPresenter}"
CanVerticallyScroll="{Binding CanVerticallyScroll, ElementName=PART_ContentPresenter}"
IsScrollInertiaEnabled="{Binding IsScrollInertiaEnabled, RelativeSource={RelativeSource TemplatedParent}}" />
</ScrollContentPresenter.GestureRecognizers>
</ScrollContentPresenter>
</DockPanel>
</Border>
</ControlTemplate> </ControlTemplate>
</Setter> </Setter>
</ControlTheme> </ControlTheme>

View File

@ -2,7 +2,21 @@
xmlns="https://github.com/avaloniaui" xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:CompileBindings="True"> x:CompileBindings="True">
<!-- Add Resources Here --> <Design.PreviewWith>
<ThemeVariantScope RequestedThemeVariant="Dark">
<MenuFlyoutPresenter>
<MenuFlyoutPresenter.Items>
<MenuItem Header="Menu Item 1" />
<MenuItem Header="Menu Item 2" />
<MenuItem Header="Menu Item 3" />
<MenuItem Header="Menu Item 4" />
<MenuItem Header="Menu Item 5" />
<MenuItem Header="Menu Item 6" />
</MenuFlyoutPresenter.Items>
</MenuFlyoutPresenter>
</ThemeVariantScope>
</Design.PreviewWith>
<ControlTheme x:Key="{x:Type MenuFlyoutPresenter}" TargetType="MenuFlyoutPresenter"> <ControlTheme x:Key="{x:Type MenuFlyoutPresenter}" TargetType="MenuFlyoutPresenter">
<Setter Property="MenuFlyoutPresenter.Background" Value="{DynamicResource MenuFlyoutBackground}" /> <Setter Property="MenuFlyoutPresenter.Background" Value="{DynamicResource MenuFlyoutBackground}" />
<Setter Property="MenuFlyoutPresenter.BorderBrush" Value="{DynamicResource MenuFlyoutBorderBrush}" /> <Setter Property="MenuFlyoutPresenter.BorderBrush" Value="{DynamicResource MenuFlyoutBorderBrush}" />
@ -23,12 +37,13 @@
BorderBrush="{TemplateBinding BorderBrush}" BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}" BorderThickness="{TemplateBinding BorderThickness}"
BoxShadow="{DynamicResource MenuFlyoutBorderBoxShadow}" BoxShadow="{DynamicResource MenuFlyoutBorderBoxShadow}"
ClipToBounds="False" ClipToBounds="True"
CornerRadius="{TemplateBinding CornerRadius}" CornerRadius="{TemplateBinding CornerRadius}"
UseLayoutRounding="False"> UseLayoutRounding="False">
<ScrollViewer <ScrollViewer
HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
Theme="{StaticResource MenuScrollViewer}" Theme="{StaticResource MenuScrollViewer}"
CornerRadius="{TemplateBinding CornerRadius}"
HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"> VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}">
<ItemsPresenter <ItemsPresenter
Name="PART_ItemsPresenter" Name="PART_ItemsPresenter"

View File

@ -4,7 +4,7 @@
<StreamGeometry x:Key="MenuItemExpandIconGlyph">M7.43934 19.7957C6.85355 19.2099 6.85355 18.2601 7.43934 17.6744L13.0962 12.0175L7.43934 6.36065C6.85355 5.77486 6.85355 4.82511 7.43934 4.23933C8.02513 3.65354 8.97487 3.65354 9.56066 4.23933L16.2782 10.9568C16.864 11.5426 16.864 12.4924 16.2782 13.0782L9.56066 19.7957C8.97487 20.3815 8.02513 20.3815 7.43934 19.7957Z</StreamGeometry> <StreamGeometry x:Key="MenuItemExpandIconGlyph">M7.43934 19.7957C6.85355 19.2099 6.85355 18.2601 7.43934 17.6744L13.0962 12.0175L7.43934 6.36065C6.85355 5.77486 6.85355 4.82511 7.43934 4.23933C8.02513 3.65354 8.97487 3.65354 9.56066 4.23933L16.2782 10.9568C16.864 11.5426 16.864 12.4924 16.2782 13.0782L9.56066 19.7957C8.97487 20.3815 8.02513 20.3815 7.43934 19.7957Z</StreamGeometry>
<!-- MenuFlyout --> <!-- MenuFlyout -->
<Thickness x:Key="MenuFlyoutBorderThickness">1</Thickness> <Thickness x:Key="MenuFlyoutBorderThickness">1</Thickness>
<Thickness x:Key="MenuFlyoutPadding">8</Thickness> <Thickness x:Key="MenuFlyoutPadding">0</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>