|
|
@ -16,6 +16,12 @@ namespace Avalonia.Controls |
|
|
[TemplatePart("PART_VerticalScrollBar", typeof(ScrollBar))] |
|
|
[TemplatePart("PART_VerticalScrollBar", typeof(ScrollBar))] |
|
|
public class ScrollViewer : ContentControl, IScrollable, IScrollAnchorProvider |
|
|
public class ScrollViewer : ContentControl, IScrollable, IScrollAnchorProvider |
|
|
{ |
|
|
{ |
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Defines the <see cref="BringIntoViewOnFocusChange "/> property.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static readonly AttachedProperty<bool> BringIntoViewOnFocusChangeProperty = |
|
|
|
|
|
AvaloniaProperty.RegisterAttached<ScrollViewer, Control, bool>(nameof(BringIntoViewOnFocusChange), true); |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Defines the <see cref="Extent"/> property.
|
|
|
/// Defines the <see cref="Extent"/> property.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
@ -174,6 +180,26 @@ namespace Avalonia.Controls |
|
|
remove => RemoveHandler(ScrollChangedEvent, value); |
|
|
remove => RemoveHandler(ScrollChangedEvent, value); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets or sets a value that determines whether the <see cref="ScrollViewer"/> uses a
|
|
|
|
|
|
/// bring-into-view scroll behavior when an item in the view gets focus.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <value>
|
|
|
|
|
|
/// true to use a behavior that brings focused items into view. false to use a behavior
|
|
|
|
|
|
/// that focused items do not automatically scroll into view. The default is true.
|
|
|
|
|
|
/// </value>
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// <see cref="BringIntoViewOnFocusChange"/> can either be set explicitly on a
|
|
|
|
|
|
/// <see cref="ScrollViewer"/>, or a the attached
|
|
|
|
|
|
/// <code>ScrollViewer.BringIntoViewOnFocusChange</code> property can be set on an element
|
|
|
|
|
|
/// that hosts a <see cref="ScrollViewer"/>.
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
public bool BringIntoViewOnFocusChange |
|
|
|
|
|
{ |
|
|
|
|
|
get => GetValue(BringIntoViewOnFocusChangeProperty); |
|
|
|
|
|
set => SetValue(BringIntoViewOnFocusChangeProperty, value); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Gets the extent of the scrollable content.
|
|
|
/// Gets the extent of the scrollable content.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
@ -400,6 +426,26 @@ namespace Avalonia.Controls |
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
public void ScrollToEnd() => SetCurrentValue(OffsetProperty, new Vector(double.NegativeInfinity, double.PositiveInfinity)); |
|
|
public void ScrollToEnd() => SetCurrentValue(OffsetProperty, new Vector(double.NegativeInfinity, double.PositiveInfinity)); |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets the value of the <see cref="BringIntoViewOnFocusChange"/> attached property.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="control">The control to read the value from.</param>
|
|
|
|
|
|
/// <returns>The value of the property.</returns>
|
|
|
|
|
|
public static bool GetBringIntoViewOnFocusChange(Control control) |
|
|
|
|
|
{ |
|
|
|
|
|
return control.GetValue(BringIntoViewOnFocusChangeProperty); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets the value of the <see cref="BringIntoViewOnFocusChange"/> attached property.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="control">The control to set the value on.</param>
|
|
|
|
|
|
/// <param name="value">The value of the property.</param>
|
|
|
|
|
|
public static void SetBringIntoViewOnFocusChange(Control control, bool value) |
|
|
|
|
|
{ |
|
|
|
|
|
control.SetValue(BringIntoViewOnFocusChangeProperty, value); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Gets the value of the HorizontalScrollBarVisibility attached property.
|
|
|
/// Gets the value of the HorizontalScrollBarVisibility attached property.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
@ -696,6 +742,14 @@ namespace Avalonia.Controls |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected override void OnGotFocus(GotFocusEventArgs e) |
|
|
|
|
|
{ |
|
|
|
|
|
base.OnGotFocus(e); |
|
|
|
|
|
|
|
|
|
|
|
if (e.Source != this && e.Source is Control c && BringIntoViewOnFocusChange) |
|
|
|
|
|
c.BringIntoView(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
protected override void OnKeyDown(KeyEventArgs e) |
|
|
protected override void OnKeyDown(KeyEventArgs e) |
|
|
{ |
|
|
{ |
|
|
if (e.Key == Key.PageUp) |
|
|
if (e.Key == Key.PageUp) |
|
|
|