enhance: add Orientation prop for ScrollViewerAttach

This commit is contained in:
NaBian committed 2021-12-21 22:48:24 +08:00
1 parent 3db85c35f8
commit ee8f18aaea
9 files changed
+58 -25

No files matched your search

@@ -10874,7 +10874,7 @@
</Border.CacheMode>
<RepeatButton Focusable="False" Style="{StaticResource RepeatButtonIcon}" Padding="8" hc:IconElement.Geometry="{StaticResource LeftGeometry}" Foreground="{DynamicResource PrimaryTextBrush}" Background="{DynamicResource SecondaryRegionBrush}" x:Name="PART_ScrollButtonLeft" />
</Border>
<hc:ScrollViewer HorizontalScrollBarVisibility="Hidden" CanMouseWheel="True" Orientation="Horizontal" IsInertiaEnabled="True" Grid.Row="0" Grid.Column="1" IsDeferredScrollingEnabled="True" x:Name="PART_OverflowScrollviewer">
<hc:ScrollViewer HorizontalScrollBarVisibility="Hidden" CanMouseWheel="True" hc:ScrollViewerAttach.Orientation="Horizontal" IsInertiaEnabled="True" Grid.Row="0" Grid.Column="1" IsDeferredScrollingEnabled="True" x:Name="PART_OverflowScrollviewer">
<Border Background="{TemplateBinding Background}" BorderThickness="0,0,0,1" BorderBrush="{DynamicResource BorderBrush}" Name="PART_HeaderBorder">
<hc:TabPanel MinHeight="{TemplateBinding TabItemHeight}" TabItemHeight="{TemplateBinding TabItemHeight}" TabItemWidth="{TemplateBinding TabItemWidth}" IsTabFillEnabled="{TemplateBinding IsTabFillEnabled}" Margin="0,0,-1,-1" x:Name="PART_HeaderPanel" HorizontalAlignment="Left" Background="{DynamicResource SecondaryTextBrush}" IsItemsHost="true" KeyboardNavigation.TabIndex="1" Panel.ZIndex="1">
<interactivity:Interaction.Behaviors>
@@ -14,7 +14,7 @@
<RowDefinition/>
</Grid.RowDefinitions>
<Border BorderThickness="1" BorderBrush="{DynamicResource BorderBrush}">
<hc:ScrollViewer Orientation="Horizontal" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Hidden" IsInertiaEnabled="True">
<hc:ScrollViewer hc:ScrollViewerAttach.Orientation="Horizontal" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Hidden" IsInertiaEnabled="True">
<StackPanel Orientation="Horizontal">
<Border Style="{StaticResource BorderRegion}" Width="200" Height="200" Margin="10,10,32,10">
<Border Background="{DynamicResource PrimaryBrush}">
@@ -32,7 +32,7 @@
</Border>
</hc:WaterfallPanel>
</hc:ScrollViewer>
<hc:ScrollViewer Margin="32,0,0,0" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Hidden" Orientation="Horizontal" MaxWidth="300">
<hc:ScrollViewer Margin="32,0,0,0" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Hidden" hc:ScrollViewerAttach.Orientation="Horizontal" MaxWidth="300">
<hc:WaterfallPanel VerticalAlignment="Center" Height="300" Orientation="Vertical" Groups="{Binding Value,ElementName=UpDownGroups}" hc:PanelElement.FluidMoveBehavior="{StaticResource BehaviorXY200}">
<Border Width="100" Background="{DynamicResource PrimaryBrush}" Effect="{StaticResource EffectShadow1}" Margin="5">
<TextBlock Text="{ex:Lang Key={x:Static langs:LangKeys.ContentDemoStr}}" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White"/>
@@ -14,7 +14,7 @@
<RowDefinition/>
</Grid.RowDefinitions>
<Border BorderThickness="1" BorderBrush="{DynamicResource BorderBrush}">
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Hidden">
<ScrollViewer hc:ScrollViewerAttach.Orientation="Horizontal" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Hidden">
<StackPanel Orientation="Horizontal">
<Border Style="{StaticResource BorderRegion}" Width="200" Height="200" Margin="10,10,32,10">
<Border Background="{DynamicResource PrimaryBrush}">
@@ -1,4 +1,6 @@
using System.Windows;
using System;
using System.Windows;
using System.Windows.Controls;
using HandyControl.Data;
namespace HandyControl.Controls
@@ -13,5 +15,42 @@ namespace HandyControl.Controls
public static bool GetAutoHide(DependencyObject element)
=> (bool) element.GetValue(AutoHideProperty);
public static readonly DependencyProperty OrientationProperty = DependencyProperty.RegisterAttached(
"Orientation", typeof(Orientation), typeof(ScrollViewerAttach), new FrameworkPropertyMetadata(ValueBoxes.VerticalBox, FrameworkPropertyMetadataOptions.Inherits, OnOrientationChanged));
private static void OnOrientationChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is ScrollViewer)
{
return;
}
if (d is System.Windows.Controls.ScrollViewer scrollViewer)
{
if ((Orientation) e.NewValue == Orientation.Horizontal)
{
scrollViewer.PreviewMouseWheel += ScrollViewer_PreviewMouseWheel;
}
else
{
scrollViewer.PreviewMouseWheel -= ScrollViewer_PreviewMouseWheel;
}
}
}
private static void ScrollViewer_PreviewMouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e)
{
var scrollViewer = (System.Windows.Controls.ScrollViewer) sender;
scrollViewer.ScrollToHorizontalOffset(Math.Min(Math.Max(0, scrollViewer.HorizontalOffset - e.Delta), scrollViewer.ScrollableWidth));
e.Handled = true;
}
public static void SetOrientation(DependencyObject element, Orientation value)
=> element.SetValue(OrientationProperty, ValueBoxes.OrientationBox(value));
public static Orientation GetOrientation(DependencyObject element)
=> (Orientation) element.GetValue(OrientationProperty);
}
}
@@ -17,21 +17,6 @@ namespace HandyControl.Controls
private bool _isRunning;
/// <summary>
/// 滚动方向
/// </summary>
public static readonly DependencyProperty OrientationProperty = DependencyProperty.Register(
"Orientation", typeof(Orientation), typeof(ScrollViewer), new PropertyMetadata(Orientation.Vertical));
/// <summary>
/// 滚动方向
/// </summary>
public Orientation Orientation
{
get => (Orientation) GetValue(OrientationProperty);
set => SetValue(OrientationProperty, value);
}
/// <summary>
/// 是否响应鼠标滚轮操作
/// </summary>
@@ -53,7 +38,7 @@ namespace HandyControl.Controls
if (!IsInertiaEnabled)
{
if (Orientation == Orientation.Vertical)
if (ScrollViewerAttach.GetOrientation(this) == Orientation.Vertical)
{
base.OnMouseWheel(e);
}
@@ -68,7 +53,7 @@ namespace HandyControl.Controls
}
e.Handled = true;
if (Orientation == Orientation.Vertical)
if (ScrollViewerAttach.GetOrientation(this) == Orientation.Vertical)
{
if (!_isRunning)
{
@@ -1,4 +1,6 @@
namespace HandyControl.Data
using System.Windows.Controls;
namespace HandyControl.Data
{
/// <summary>
/// 装箱后的值类型(用于提高效率)
@@ -9,6 +11,10 @@
internal static object FalseBox = false;
internal static object VerticalBox = Orientation.Vertical;
internal static object HorizontalBox = Orientation.Horizontal;
internal static object Double0Box = .0;
internal static object Double01Box = .1;
@@ -38,5 +44,8 @@
internal static object Int99Box = 99;
internal static object BooleanBox(bool value) => value ? TrueBox : FalseBox;
internal static object OrientationBox(Orientation value) =>
value == Orientation.Horizontal ? HorizontalBox : VerticalBox;
}
}
@@ -291,7 +291,7 @@
</Border.CacheMode>
<RepeatButton Focusable="False" Style="{StaticResource RepeatButtonIcon}" Padding="8" hc:IconElement.Geometry="{StaticResource LeftGeometry}" Foreground="{DynamicResource PrimaryTextBrush}" Background="{DynamicResource SecondaryRegionBrush}" x:Name="PART_ScrollButtonLeft"/>
</Border>
<hc:ScrollViewer HorizontalScrollBarVisibility="Hidden" CanMouseWheel="True" Orientation="Horizontal" IsInertiaEnabled="True" Grid.Row="0" Grid.Column="1" IsDeferredScrollingEnabled="True" x:Name="PART_OverflowScrollviewer">
<hc:ScrollViewer HorizontalScrollBarVisibility="Hidden" CanMouseWheel="True" hc:ScrollViewerAttach.Orientation="Horizontal" IsInertiaEnabled="True" Grid.Row="0" Grid.Column="1" IsDeferredScrollingEnabled="True" x:Name="PART_OverflowScrollviewer">
<Border Background="{TemplateBinding Background}" BorderThickness="0,0,0,1" BorderBrush="{DynamicResource BorderBrush}" Name="PART_HeaderBorder">
<hc:TabPanel MinHeight="{TemplateBinding TabItemHeight}" TabItemHeight="{TemplateBinding TabItemHeight}" TabItemWidth="{TemplateBinding TabItemWidth}" IsTabFillEnabled="{TemplateBinding IsTabFillEnabled}" Margin="0,0,-1,-1" x:Name="PART_HeaderPanel" HorizontalAlignment="Left" Background="{DynamicResource SecondaryTextBrush}" IsItemsHost="true" KeyboardNavigation.TabIndex="1" Panel.ZIndex="1">
<interactivity:Interaction.Behaviors>
@@ -10992,7 +10992,7 @@
</Border.CacheMode>
<RepeatButton Focusable="False" Style="{StaticResource RepeatButtonIcon}" Padding="8" hc:IconElement.Geometry="{StaticResource LeftGeometry}" Foreground="{DynamicResource PrimaryTextBrush}" Background="{DynamicResource SecondaryRegionBrush}" x:Name="PART_ScrollButtonLeft" />
</Border>
<hc:ScrollViewer HorizontalScrollBarVisibility="Hidden" CanMouseWheel="True" Orientation="Horizontal" IsInertiaEnabled="True" Grid.Row="0" Grid.Column="1" IsDeferredScrollingEnabled="True" x:Name="PART_OverflowScrollviewer">
<hc:ScrollViewer HorizontalScrollBarVisibility="Hidden" CanMouseWheel="True" hc:ScrollViewerAttach.Orientation="Horizontal" IsInertiaEnabled="True" Grid.Row="0" Grid.Column="1" IsDeferredScrollingEnabled="True" x:Name="PART_OverflowScrollviewer">
<Border Background="{TemplateBinding Background}" BorderThickness="0,0,0,1" BorderBrush="{DynamicResource BorderBrush}" Name="PART_HeaderBorder">
<hc:TabPanel MinHeight="{TemplateBinding TabItemHeight}" TabItemHeight="{TemplateBinding TabItemHeight}" TabItemWidth="{TemplateBinding TabItemWidth}" IsTabFillEnabled="{TemplateBinding IsTabFillEnabled}" Margin="0,0,-1,-1" x:Name="PART_HeaderPanel" HorizontalAlignment="Left" Background="{DynamicResource SecondaryTextBrush}" IsItemsHost="true" KeyboardNavigation.TabIndex="1" Panel.ZIndex="1">
<interactivity:Interaction.Behaviors>