Browse Source

Merge pull request #7279 from timunie/feature/ScrollViewerBubbleUp

ScrollViewer add property to bubble up the scroll event if not handled by nested ScrollViewer
pull/7476/head
Max Katz 5 years ago
committed by GitHub
parent
commit
825a024711
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      src/Avalonia.Controls.DataGrid/DataGrid.cs
  2. 34
      src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs
  3. 52
      src/Avalonia.Controls/ScrollViewer.cs
  4. 2
      src/Avalonia.Themes.Default/Controls/ListBox.xaml
  5. 3
      src/Avalonia.Themes.Default/Controls/ScrollViewer.xaml
  6. 2
      src/Avalonia.Themes.Default/Controls/TextBox.xaml
  7. 2
      src/Avalonia.Themes.Default/Controls/TreeView.xaml
  8. 2
      src/Avalonia.Themes.Fluent/Controls/ListBox.xaml
  9. 3
      src/Avalonia.Themes.Fluent/Controls/ScrollViewer.xaml
  10. 2
      src/Avalonia.Themes.Fluent/Controls/TextBox.xaml
  11. 2
      src/Avalonia.Themes.Fluent/Controls/TreeView.xaml

9
src/Avalonia.Controls.DataGrid/DataGrid.cs

@ -2215,7 +2215,14 @@ namespace Avalonia.Controls
/// <param name="e">PointerWheelEventArgs</param> /// <param name="e">PointerWheelEventArgs</param>
protected override void OnPointerWheelChanged(PointerWheelEventArgs e) protected override void OnPointerWheelChanged(PointerWheelEventArgs e)
{ {
e.Handled = e.Handled || UpdateScroll(e.Delta * DATAGRID_mouseWheelDelta); if(UpdateScroll(e.Delta * DATAGRID_mouseWheelDelta))
{
e.Handled = true;
}
else
{
e.Handled = e.Handled || !ScrollViewer.GetIsScrollChainingEnabled(this);
}
} }
internal bool UpdateScroll(Vector delta) internal bool UpdateScroll(Vector delta)

34
src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs

@ -60,6 +60,12 @@ namespace Avalonia.Controls.Presenters
o => o.Viewport, o => o.Viewport,
(o, v) => o.Viewport = v); (o, v) => o.Viewport = v);
/// <summary>
/// Defines the <see cref="IsScrollChainingEnabled"/> property.
/// </summary>
public static readonly StyledProperty<bool> IsScrollChainingEnabledProperty =
ScrollViewer.IsScrollChainingEnabledProperty.AddOwner<ScrollContentPresenter>();
private bool _canHorizontallyScroll; private bool _canHorizontallyScroll;
private bool _canVerticallyScroll; private bool _canVerticallyScroll;
private bool _arranging; private bool _arranging;
@ -138,6 +144,20 @@ namespace Avalonia.Controls.Presenters
private set { SetAndRaise(ViewportProperty, ref _viewport, value); } private set { SetAndRaise(ViewportProperty, ref _viewport, value); }
} }
/// <summary>
/// Gets or sets if scroll chaining is enabled. The default value is true.
/// </summary>
/// <remarks>
/// After a user hits a scroll limit on an element that has been nested within another scrollable element,
/// you can specify whether that parent element should continue the scrolling operation begun in its child element.
/// This is called scroll chaining.
/// </remarks>
public bool IsScrollChainingEnabled
{
get => GetValue(IsScrollChainingEnabledProperty);
set => SetValue(IsScrollChainingEnabledProperty, value);
}
/// <inheritdoc/> /// <inheritdoc/>
IControl? IScrollAnchorProvider.CurrentAnchor IControl? IScrollAnchorProvider.CurrentAnchor
{ {
@ -405,8 +425,11 @@ namespace Avalonia.Controls.Presenters
_activeLogicalGestureScrolls[e.Id] = delta; _activeLogicalGestureScrolls[e.Id] = delta;
} }
Offset = new Vector(x, y); Vector newOffset = new Vector(x, y);
e.Handled = true; bool offsetChanged = newOffset != Offset;
Offset = newOffset;
e.Handled = !IsScrollChainingEnabled || offsetChanged;
} }
} }
@ -440,8 +463,11 @@ namespace Avalonia.Controls.Presenters
x = Math.Min(x, Extent.Width - Viewport.Width); x = Math.Min(x, Extent.Width - Viewport.Width);
} }
Offset = new Vector(x, y); Vector newOffset = new Vector(x, y);
e.Handled = true; bool offsetChanged = newOffset != Offset;
Offset = newOffset;
e.Handled = !IsScrollChainingEnabled || offsetChanged;
} }
} }

52
src/Avalonia.Controls/ScrollViewer.cs

@ -181,6 +181,14 @@ namespace Avalonia.Controls
nameof(AllowAutoHide), nameof(AllowAutoHide),
true); true);
/// <summary>
/// Defines the <see cref="IsScrollChainingEnabled"/> property.
/// </summary>
public static readonly AttachedProperty<bool> IsScrollChainingEnabledProperty =
AvaloniaProperty.RegisterAttached<ScrollViewer, Control, bool>(
nameof(IsScrollChainingEnabled),
defaultValue: true);
/// <summary> /// <summary>
/// Defines the <see cref="ScrollChanged"/> event. /// Defines the <see cref="ScrollChanged"/> event.
/// </summary> /// </summary>
@ -418,6 +426,20 @@ namespace Avalonia.Controls
set => SetValue(AllowAutoHideProperty, value); set => SetValue(AllowAutoHideProperty, value);
} }
/// <summary>
/// Gets or sets if scroll chaining is enabled. The default value is true.
/// </summary>
/// <remarks>
/// After a user hits a scroll limit on an element that has been nested within another scrollable element,
/// you can specify whether that parent element should continue the scrolling operation begun in its child element.
/// This is called scroll chaining.
/// </remarks>
public bool IsScrollChainingEnabled
{
get => GetValue(IsScrollChainingEnabledProperty);
set => SetValue(IsScrollChainingEnabledProperty, value);
}
/// <summary> /// <summary>
/// Scrolls the content up one line. /// Scrolls the content up one line.
/// </summary> /// </summary>
@ -548,6 +570,36 @@ namespace Avalonia.Controls
return control.GetValue(AllowAutoHideProperty); return control.GetValue(AllowAutoHideProperty);
} }
/// <summary>
/// Sets the value of the IsScrollChainingEnabled attached property.
/// </summary>
/// <param name="control">The control to set the value on.</param>
/// <param name="value">The value of the property.</param>
/// <remarks>
/// After a user hits a scroll limit on an element that has been nested within another scrollable element,
/// you can specify whether that parent element should continue the scrolling operation begun in its child element.
/// This is called scroll chaining.
/// </remarks>
public static void SetIsScrollChainingEnabled(Control control, bool value)
{
control.SetValue(IsScrollChainingEnabledProperty, value);
}
/// <summary>
/// Gets the value of the IsScrollChainingEnabled attached property.
/// </summary>
/// <param name="control">The control to read the value from.</param>
/// <returns>The value of the property.</returns>
/// <remarks>
/// After a user hits a scroll limit on an element that has been nested within another scrollable element,
/// you can specify whether that parent element should continue the scrolling operation begun in its child element.
/// This is called scroll chaining.
/// </remarks>
public static bool GetIsScrollChainingEnabled(Control control)
{
return control.GetValue(IsScrollChainingEnabledProperty);
}
/// <summary> /// <summary>
/// Gets the value of the VerticalScrollBarVisibility attached property. /// Gets the value of the VerticalScrollBarVisibility attached property.
/// </summary> /// </summary>

2
src/Avalonia.Themes.Default/Controls/ListBox.xaml

@ -6,6 +6,7 @@
<Setter Property="Padding" Value="4"/> <Setter Property="Padding" Value="4"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/> <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/> <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.IsScrollChainingEnabled" Value="True" />
<Setter Property="Template"> <Setter Property="Template">
<ControlTemplate> <ControlTemplate>
<Border Name="border" BorderBrush="{TemplateBinding BorderBrush}" <Border Name="border" BorderBrush="{TemplateBinding BorderBrush}"
@ -15,6 +16,7 @@
Background="{TemplateBinding Background}" Background="{TemplateBinding Background}"
HorizontalScrollBarVisibility="{TemplateBinding (ScrollViewer.HorizontalScrollBarVisibility)}" HorizontalScrollBarVisibility="{TemplateBinding (ScrollViewer.HorizontalScrollBarVisibility)}"
VerticalScrollBarVisibility="{TemplateBinding (ScrollViewer.VerticalScrollBarVisibility)}" VerticalScrollBarVisibility="{TemplateBinding (ScrollViewer.VerticalScrollBarVisibility)}"
IsScrollChainingEnabled="{TemplateBinding (ScrollViewer.IsScrollChainingEnabled)}"
AllowAutoHide="{TemplateBinding (ScrollViewer.AllowAutoHide)}"> AllowAutoHide="{TemplateBinding (ScrollViewer.AllowAutoHide)}">
<ItemsPresenter Name="PART_ItemsPresenter" <ItemsPresenter Name="PART_ItemsPresenter"
Items="{TemplateBinding Items}" Items="{TemplateBinding Items}"

3
src/Avalonia.Themes.Default/Controls/ScrollViewer.xaml

@ -15,7 +15,8 @@
Extent="{TemplateBinding Extent, Mode=TwoWay}" Extent="{TemplateBinding Extent, Mode=TwoWay}"
Margin="{TemplateBinding Padding}" Margin="{TemplateBinding Padding}"
Offset="{TemplateBinding Offset, Mode=TwoWay}" Offset="{TemplateBinding Offset, Mode=TwoWay}"
Viewport="{TemplateBinding Viewport, Mode=TwoWay}"> Viewport="{TemplateBinding Viewport, Mode=TwoWay}"
IsScrollChainingEnabled="{TemplateBinding IsScrollChainingEnabled}">
<ScrollContentPresenter.GestureRecognizers> <ScrollContentPresenter.GestureRecognizers>
<ScrollGestureRecognizer <ScrollGestureRecognizer
CanHorizontallyScroll="{TemplateBinding CanHorizontallyScroll}" CanHorizontallyScroll="{TemplateBinding CanHorizontallyScroll}"

2
src/Avalonia.Themes.Default/Controls/TextBox.xaml

@ -25,6 +25,7 @@
<Setter Property="SelectionForegroundBrush" Value="{DynamicResource HighlightForegroundBrush}"/> <Setter Property="SelectionForegroundBrush" Value="{DynamicResource HighlightForegroundBrush}"/>
<Setter Property="Padding" Value="4"/> <Setter Property="Padding" Value="4"/>
<Setter Property="ContextFlyout" Value="{StaticResource DefaultTextBoxContextFlyout}" /> <Setter Property="ContextFlyout" Value="{StaticResource DefaultTextBoxContextFlyout}" />
<Setter Property="ScrollViewer.IsScrollChainingEnabled" Value="True" />
<Setter Property="Template"> <Setter Property="Template">
<ControlTemplate> <ControlTemplate>
<Border Name="border" <Border Name="border"
@ -59,6 +60,7 @@
<ScrollViewer Grid.Column="1" Grid.ColumnSpan="1" <ScrollViewer Grid.Column="1" Grid.ColumnSpan="1"
HorizontalScrollBarVisibility="{TemplateBinding (ScrollViewer.HorizontalScrollBarVisibility)}" HorizontalScrollBarVisibility="{TemplateBinding (ScrollViewer.HorizontalScrollBarVisibility)}"
VerticalScrollBarVisibility="{TemplateBinding (ScrollViewer.VerticalScrollBarVisibility)}" VerticalScrollBarVisibility="{TemplateBinding (ScrollViewer.VerticalScrollBarVisibility)}"
IsScrollChainingEnabled="{TemplateBinding (ScrollViewer.IsScrollChainingEnabled)}"
AllowAutoHide="{TemplateBinding (ScrollViewer.AllowAutoHide)}"> AllowAutoHide="{TemplateBinding (ScrollViewer.AllowAutoHide)}">
<Panel> <Panel>
<TextBlock Name="watermark" <TextBlock Name="watermark"

2
src/Avalonia.Themes.Default/Controls/TreeView.xaml

@ -5,6 +5,7 @@
<Setter Property="Padding" Value="4"/> <Setter Property="Padding" Value="4"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/> <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/> <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.IsScrollChainingEnabled" Value="True" />
<Setter Property="Template"> <Setter Property="Template">
<ControlTemplate> <ControlTemplate>
<Border BorderBrush="{TemplateBinding BorderBrush}" <Border BorderBrush="{TemplateBinding BorderBrush}"
@ -13,6 +14,7 @@
<ScrollViewer Background="{TemplateBinding Background}" <ScrollViewer Background="{TemplateBinding Background}"
HorizontalScrollBarVisibility="{TemplateBinding (ScrollViewer.HorizontalScrollBarVisibility)}" HorizontalScrollBarVisibility="{TemplateBinding (ScrollViewer.HorizontalScrollBarVisibility)}"
VerticalScrollBarVisibility="{TemplateBinding (ScrollViewer.VerticalScrollBarVisibility)}" VerticalScrollBarVisibility="{TemplateBinding (ScrollViewer.VerticalScrollBarVisibility)}"
IsScrollChainingEnabled="{TemplateBinding (ScrollViewer.IsScrollChainingEnabled)}"
AllowAutoHide="{TemplateBinding (ScrollViewer.AllowAutoHide)}"> AllowAutoHide="{TemplateBinding (ScrollViewer.AllowAutoHide)}">
<ItemsPresenter Name="PART_ItemsPresenter" <ItemsPresenter Name="PART_ItemsPresenter"
Items="{TemplateBinding Items}" Items="{TemplateBinding Items}"

2
src/Avalonia.Themes.Fluent/Controls/ListBox.xaml

@ -16,6 +16,7 @@
<Setter Property="BorderThickness" Value="{DynamicResource ListBoxBorderThemeThickness}" /> <Setter Property="BorderThickness" Value="{DynamicResource ListBoxBorderThemeThickness}" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" /> <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" />
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" /> <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
<Setter Property="ScrollViewer.IsScrollChainingEnabled" Value="True" />
<Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}" /> <Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}" />
<Setter Property="Template"> <Setter Property="Template">
<ControlTemplate> <ControlTemplate>
@ -28,6 +29,7 @@
<ScrollViewer Name="PART_ScrollViewer" <ScrollViewer Name="PART_ScrollViewer"
HorizontalScrollBarVisibility="{TemplateBinding (ScrollViewer.HorizontalScrollBarVisibility)}" HorizontalScrollBarVisibility="{TemplateBinding (ScrollViewer.HorizontalScrollBarVisibility)}"
VerticalScrollBarVisibility="{TemplateBinding (ScrollViewer.VerticalScrollBarVisibility)}" VerticalScrollBarVisibility="{TemplateBinding (ScrollViewer.VerticalScrollBarVisibility)}"
IsScrollChainingEnabled="{TemplateBinding (ScrollViewer.IsScrollChainingEnabled)}"
AllowAutoHide="{TemplateBinding (ScrollViewer.AllowAutoHide)}"> AllowAutoHide="{TemplateBinding (ScrollViewer.AllowAutoHide)}">
<ItemsPresenter Name="PART_ItemsPresenter" <ItemsPresenter Name="PART_ItemsPresenter"
Items="{TemplateBinding Items}" Items="{TemplateBinding Items}"

3
src/Avalonia.Themes.Fluent/Controls/ScrollViewer.xaml

@ -34,7 +34,8 @@
Extent="{TemplateBinding Extent, Mode=TwoWay}" Extent="{TemplateBinding Extent, Mode=TwoWay}"
Margin="{TemplateBinding Padding}" Margin="{TemplateBinding Padding}"
Offset="{TemplateBinding Offset, Mode=TwoWay}" Offset="{TemplateBinding Offset, Mode=TwoWay}"
Viewport="{TemplateBinding Viewport, Mode=TwoWay}"> Viewport="{TemplateBinding Viewport, Mode=TwoWay}"
IsScrollChainingEnabled="{TemplateBinding IsScrollChainingEnabled}">
<ScrollContentPresenter.GestureRecognizers> <ScrollContentPresenter.GestureRecognizers>
<ScrollGestureRecognizer <ScrollGestureRecognizer
CanHorizontallyScroll="{TemplateBinding CanHorizontallyScroll}" CanHorizontallyScroll="{TemplateBinding CanHorizontallyScroll}"

2
src/Avalonia.Themes.Fluent/Controls/TextBox.xaml

@ -41,6 +41,7 @@
<Setter Property="MinWidth" Value="{DynamicResource TextControlThemeMinWidth}" /> <Setter Property="MinWidth" Value="{DynamicResource TextControlThemeMinWidth}" />
<Setter Property="Padding" Value="{DynamicResource TextControlThemePadding}" /> <Setter Property="Padding" Value="{DynamicResource TextControlThemePadding}" />
<Setter Property="FocusAdorner" Value="{x:Null}" /> <Setter Property="FocusAdorner" Value="{x:Null}" />
<Setter Property="ScrollViewer.IsScrollChainingEnabled" Value="True" />
<Setter Property="ContextFlyout" Value="{StaticResource DefaultTextBoxContextFlyout}" /> <Setter Property="ContextFlyout" Value="{StaticResource DefaultTextBoxContextFlyout}" />
<Setter Property="Template"> <Setter Property="Template">
<ControlTemplate> <ControlTemplate>
@ -68,6 +69,7 @@
DockPanel.Dock="Top" /> DockPanel.Dock="Top" />
<ScrollViewer HorizontalScrollBarVisibility="{TemplateBinding (ScrollViewer.HorizontalScrollBarVisibility)}" <ScrollViewer HorizontalScrollBarVisibility="{TemplateBinding (ScrollViewer.HorizontalScrollBarVisibility)}"
VerticalScrollBarVisibility="{TemplateBinding (ScrollViewer.VerticalScrollBarVisibility)}" VerticalScrollBarVisibility="{TemplateBinding (ScrollViewer.VerticalScrollBarVisibility)}"
IsScrollChainingEnabled="{TemplateBinding (ScrollViewer.IsScrollChainingEnabled)}"
AllowAutoHide="{TemplateBinding (ScrollViewer.AllowAutoHide)}"> AllowAutoHide="{TemplateBinding (ScrollViewer.AllowAutoHide)}">
<Panel> <Panel>
<TextBlock Name="PART_Watermark" <TextBlock Name="PART_Watermark"

2
src/Avalonia.Themes.Fluent/Controls/TreeView.xaml

@ -6,6 +6,7 @@
<Setter Property="Padding" Value="0" /> <Setter Property="Padding" Value="0" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" /> <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" />
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" /> <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
<Setter Property="ScrollViewer.IsScrollChainingEnabled" Value="True" />
<Setter Property="Template"> <Setter Property="Template">
<ControlTemplate> <ControlTemplate>
<Border BorderBrush="{TemplateBinding BorderBrush}" <Border BorderBrush="{TemplateBinding BorderBrush}"
@ -14,6 +15,7 @@
<ScrollViewer Background="{TemplateBinding Background}" <ScrollViewer Background="{TemplateBinding Background}"
HorizontalScrollBarVisibility="{TemplateBinding (ScrollViewer.HorizontalScrollBarVisibility)}" HorizontalScrollBarVisibility="{TemplateBinding (ScrollViewer.HorizontalScrollBarVisibility)}"
VerticalScrollBarVisibility="{TemplateBinding (ScrollViewer.VerticalScrollBarVisibility)}" VerticalScrollBarVisibility="{TemplateBinding (ScrollViewer.VerticalScrollBarVisibility)}"
IsScrollChainingEnabled="{TemplateBinding (ScrollViewer.IsScrollChainingEnabled)}"
AllowAutoHide="{TemplateBinding (ScrollViewer.AllowAutoHide)}"> AllowAutoHide="{TemplateBinding (ScrollViewer.AllowAutoHide)}">
<ItemsPresenter Name="PART_ItemsPresenter" <ItemsPresenter Name="PART_ItemsPresenter"
Items="{TemplateBinding Items}" Items="{TemplateBinding Items}"

Loading…
Cancel
Save