Table of Contents

Class ScrollViewer

Namespace
Avalonia.Controls
Assembly
Avalonia.Controls.dll

A control which scrolls its content if the content is bigger than the space available.

[TemplatePart("PART_HorizontalScrollBar", typeof(ScrollBar))]
[TemplatePart("PART_VerticalScrollBar", typeof(ScrollBar))]
public class ScrollViewer : ContentControl, INotifyPropertyChanged, IDataContextProvider, ILogical, IThemeVariantHost, IResourceHost, IResourceNode, IStyleHost, ISetLogicalParent, ISetInheritanceParent, ISupportInitialize, IStyleable, INamed, IInputElement, IDataTemplateHost, ISetterValue, IScrollable, IScrollAnchorProvider
Inheritance
ScrollViewer
Implements
Inherited Members
Extension Methods

Constructors

ScrollViewer()

Initializes a new instance of the ScrollViewer class.

public ScrollViewer()

Fields

AllowAutoHideProperty

Defines the AllowAutoHide property.

public static readonly AttachedProperty<bool> AllowAutoHideProperty

Field Value

AttachedProperty<bool>

BringIntoViewOnFocusChangeProperty

Defines the BringIntoViewOnFocusChange property.

public static readonly AttachedProperty<bool> BringIntoViewOnFocusChangeProperty

Field Value

AttachedProperty<bool>

ExtentProperty

Defines the Extent property.

public static readonly DirectProperty<ScrollViewer, Size> ExtentProperty

Field Value

DirectProperty<ScrollViewer, Size>

HorizontalScrollBarVisibilityProperty

Defines the HorizontalScrollBarVisibility property.

public static readonly AttachedProperty<ScrollBarVisibility> HorizontalScrollBarVisibilityProperty

Field Value

AttachedProperty<ScrollBarVisibility>

HorizontalSnapPointsAlignmentProperty

Defines the HorizontalSnapPointsAlignment property.

public static readonly AttachedProperty<SnapPointsAlignment> HorizontalSnapPointsAlignmentProperty

Field Value

AttachedProperty<SnapPointsAlignment>

HorizontalSnapPointsTypeProperty

Defines the HorizontalSnapPointsType property.

public static readonly AttachedProperty<SnapPointsType> HorizontalSnapPointsTypeProperty

Field Value

AttachedProperty<SnapPointsType>

IsDeferredScrollingEnabledProperty

Defines the IsDeferredScrollingEnabled property.

public static readonly AttachedProperty<bool> IsDeferredScrollingEnabledProperty

Field Value

AttachedProperty<bool>

IsExpandedProperty

Defines the IsExpanded property.

public static readonly DirectProperty<ScrollViewer, bool> IsExpandedProperty

Field Value

DirectProperty<ScrollViewer, bool>

IsScrollChainingEnabledProperty

Defines the IsScrollChainingEnabled property.

public static readonly AttachedProperty<bool> IsScrollChainingEnabledProperty

Field Value

AttachedProperty<bool>

IsScrollInertiaEnabledProperty

Defines the IsScrollInertiaEnabled property.

public static readonly AttachedProperty<bool> IsScrollInertiaEnabledProperty

Field Value

AttachedProperty<bool>

LargeChangeProperty

Defines the LargeChange property.

public static readonly DirectProperty<ScrollViewer, Size> LargeChangeProperty

Field Value

DirectProperty<ScrollViewer, Size>

OffsetProperty

Defines the Offset property.

public static readonly StyledProperty<Vector> OffsetProperty

Field Value

StyledProperty<Vector>

ScrollBarMaximumProperty

Defines the ScrollBarMaximum property.

public static readonly DirectProperty<ScrollViewer, Vector> ScrollBarMaximumProperty

Field Value

DirectProperty<ScrollViewer, Vector>

ScrollChangedEvent

Defines the ScrollChanged event.

public static readonly RoutedEvent<ScrollChangedEventArgs> ScrollChangedEvent

Field Value

RoutedEvent<ScrollChangedEventArgs>

SmallChangeProperty

Defines the SmallChange property.

public static readonly DirectProperty<ScrollViewer, Size> SmallChangeProperty

Field Value

DirectProperty<ScrollViewer, Size>

VerticalScrollBarVisibilityProperty

Defines the VerticalScrollBarVisibility property.

public static readonly AttachedProperty<ScrollBarVisibility> VerticalScrollBarVisibilityProperty

Field Value

AttachedProperty<ScrollBarVisibility>

VerticalSnapPointsAlignmentProperty

Defines the VerticalSnapPointsAlignment property.

public static readonly AttachedProperty<SnapPointsAlignment> VerticalSnapPointsAlignmentProperty

Field Value

AttachedProperty<SnapPointsAlignment>

VerticalSnapPointsTypeProperty

Defines the VerticalSnapPointsType property.

public static readonly AttachedProperty<SnapPointsType> VerticalSnapPointsTypeProperty

Field Value

AttachedProperty<SnapPointsType>

ViewportProperty

Defines the Viewport property.

public static readonly DirectProperty<ScrollViewer, Size> ViewportProperty

Field Value

DirectProperty<ScrollViewer, Size>

Properties

AllowAutoHide

Gets a value that indicates whether scrollbars can hide itself when user is not interacting with it.

public bool AllowAutoHide { get; set; }

Property Value

bool

BringIntoViewOnFocusChange

Gets or sets a value that determines whether the ScrollViewer uses a bring-into-view scroll behavior when an item in the view gets focus.

public bool BringIntoViewOnFocusChange { get; set; }

Property Value

bool

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.

Remarks

BringIntoViewOnFocusChange can either be set explicitly on a ScrollViewer, or a the attached

ScrollViewer.BringIntoViewOnFocusChange
property can be set on an element that hosts a ScrollViewer.

CanHorizontallyScroll

Gets a value indicating whether the viewer can scroll horizontally.

protected bool CanHorizontallyScroll { get; }

Property Value

bool

CanVerticallyScroll

Gets a value indicating whether the viewer can scroll vertically.

protected bool CanVerticallyScroll { get; }

Property Value

bool

CurrentAnchor

The currently chosen anchor element to use for scroll anchoring.

public Control? CurrentAnchor { get; }

Property Value

Control

Extent

Gets the extent of the scrollable content.

public Size Extent { get; }

Property Value

Size

HorizontalScrollBarVisibility

Gets or sets the horizontal scrollbar visibility.

public ScrollBarVisibility HorizontalScrollBarVisibility { get; set; }

Property Value

ScrollBarVisibility

HorizontalSnapPointsAlignment

Gets or sets how the existing snap points are horizontally aligned versus the initial viewport.

public SnapPointsAlignment HorizontalSnapPointsAlignment { get; set; }

Property Value

SnapPointsAlignment

HorizontalSnapPointsType

Gets or sets how scroll gesture reacts to the snap points along the horizontal axis.

public SnapPointsType HorizontalSnapPointsType { get; set; }

Property Value

SnapPointsType

IsDeferredScrollingEnabled

Gets or sets whether dragging of Thumb elements should update the ScrollViewer only when the user releases the mouse.

public bool IsDeferredScrollingEnabled { get; set; }

Property Value

bool

IsExpanded

Gets a value that indicates whether any scrollbar is expanded.

public bool IsExpanded { get; }

Property Value

bool

IsScrollChainingEnabled

Gets or sets if scroll chaining is enabled. The default value is true.

public bool IsScrollChainingEnabled { get; set; }

Property Value

bool

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.

IsScrollInertiaEnabled

Gets or sets whether scroll gestures should include inertia in their behavior and value.

public bool IsScrollInertiaEnabled { get; set; }

Property Value

bool

LargeChange

Gets the large (page) change value for the scroll viewer.

public Size LargeChange { get; }

Property Value

Size

Offset

Gets or sets the current scroll offset.

public Vector Offset { get; set; }

Property Value

Vector

ScrollBarMaximum

Gets the maximum scrolling distance (which is Extent - Viewport).

public Vector ScrollBarMaximum { get; }

Property Value

Vector

SmallChange

Gets the small (line) change value for the scroll viewer.

public Size SmallChange { get; }

Property Value

Size

VerticalScrollBarVisibility

Gets or sets the vertical scrollbar visibility.

public ScrollBarVisibility VerticalScrollBarVisibility { get; set; }

Property Value

ScrollBarVisibility

VerticalSnapPointsAlignment

Gets or sets how the existing snap points are vertically aligned versus the initial viewport.

public SnapPointsAlignment VerticalSnapPointsAlignment { get; set; }

Property Value

SnapPointsAlignment

VerticalSnapPointsType

Gets or sets how scroll gesture reacts to the snap points along the vertical axis.

public SnapPointsType VerticalSnapPointsType { get; set; }

Property Value

SnapPointsType

Viewport

Gets the size of the viewport on the scrollable content.

public Size Viewport { get; }

Property Value

Size

Methods

GetAllowAutoHide(Control)

Gets the value of the AllowAutoHideProperty attached property.

public static bool GetAllowAutoHide(Control control)

Parameters

control Control

The control to read the value from.

Returns

bool

The value of the property.

GetBringIntoViewOnFocusChange(Control)

Gets the value of the BringIntoViewOnFocusChange attached property.

public static bool GetBringIntoViewOnFocusChange(Control control)

Parameters

control Control

The control to read the value from.

Returns

bool

The value of the property.

GetHorizontalScrollBarVisibility(Control)

Gets the value of the HorizontalScrollBarVisibility attached property.

public static ScrollBarVisibility GetHorizontalScrollBarVisibility(Control control)

Parameters

control Control

The control to read the value from.

Returns

ScrollBarVisibility

The value of the property.

GetHorizontalSnapPointsAlignment(Control)

Gets the value of the HorizontalSnapPointsAlignment attached property.

public static SnapPointsAlignment GetHorizontalSnapPointsAlignment(Control control)

Parameters

control Control

The control to read the value from.

Returns

SnapPointsAlignment

The value of the property.

GetHorizontalSnapPointsType(Control)

Gets the value of the HorizontalSnapPointsType attached property.

public static SnapPointsType GetHorizontalSnapPointsType(Control control)

Parameters

control Control

The control to read the value from.

Returns

SnapPointsType

The value of the property.

GetIsDeferredScrollingEnabled(Control)

Gets whether dragging of Thumb elements should update the ScrollViewer only when the user releases the mouse.

public static bool GetIsDeferredScrollingEnabled(Control control)

Parameters

control Control

Returns

bool

GetIsScrollChainingEnabled(Control)

Gets the value of the IsScrollChainingEnabled attached property.

public static bool GetIsScrollChainingEnabled(Control control)

Parameters

control Control

The control to read the value from.

Returns

bool

The value of the property.

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.

GetIsScrollInertiaEnabled(Control)

Gets whether scroll gestures should include inertia in their behavior and value.

public static bool GetIsScrollInertiaEnabled(Control control)

Parameters

control Control

Returns

bool

GetVerticalScrollBarVisibility(Control)

Gets the value of the VerticalScrollBarVisibility attached property.

public static ScrollBarVisibility GetVerticalScrollBarVisibility(Control control)

Parameters

control Control

The control to read the value from.

Returns

ScrollBarVisibility

The value of the property.

GetVerticalSnapPointsAlignment(Control)

Gets the value of the VerticalSnapPointsAlignment attached property.

public static SnapPointsAlignment GetVerticalSnapPointsAlignment(Control control)

Parameters

control Control

The control to read the value from.

Returns

SnapPointsAlignment

The value of the property.

GetVerticalSnapPointsType(Control)

Gets the value of the VerticalSnapPointsType attached property.

public static SnapPointsType GetVerticalSnapPointsType(Control control)

Parameters

control Control

The control to read the value from.

Returns

SnapPointsType

The value of the property.

LineDown()

Scrolls the content down one line.

public void LineDown()

LineLeft()

Scrolls the content left one line.

public void LineLeft()

LineRight()

Scrolls the content right one line.

public void LineRight()

LineUp()

Scrolls the content up one line.

public void LineUp()

OnApplyTemplate(TemplateAppliedEventArgs)

Called when the control's template is applied. In simple terms, this means the method is called just before the control is displayed.

protected override void OnApplyTemplate(TemplateAppliedEventArgs e)

Parameters

e TemplateAppliedEventArgs

The event args.

OnCreateAutomationPeer()

Returns a new, type-specific AutomationPeer implementation for the control.

protected override AutomationPeer OnCreateAutomationPeer()

Returns

AutomationPeer

The type-specific AutomationPeer implementation.

OnGotFocus(GotFocusEventArgs)

Called before the GotFocus event occurs.

protected override void OnGotFocus(GotFocusEventArgs e)

Parameters

e GotFocusEventArgs

The event args.

OnKeyDown(KeyEventArgs)

Called before the KeyDown event occurs.

protected override void OnKeyDown(KeyEventArgs e)

Parameters

e KeyEventArgs

The event args.

OnPropertyChanged(AvaloniaPropertyChangedEventArgs)

Called when a avalonia property changes on the object.

protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)

Parameters

change AvaloniaPropertyChangedEventArgs

The property change details.

OnScrollChanged(ScrollChangedEventArgs)

Called when a change in scrolling state is detected, such as a change in scroll position, extent, or viewport size.

protected virtual void OnScrollChanged(ScrollChangedEventArgs e)

Parameters

e ScrollChangedEventArgs

The event args.

Remarks

If you override this method, call base.OnScrollChanged(ScrollChangedEventArgs) to ensure that this event is raised.

PageDown()

Scrolls the content downward by one page.

public void PageDown()

PageLeft()

Scrolls the content left by one page.

public void PageLeft()

PageRight()

Scrolls the content tight by one page.

public void PageRight()

PageUp()

Scrolls the content upward by one page.

public void PageUp()

RegisterAnchorCandidate(Control)

Registers a control as a potential scroll anchor candidate.

public void RegisterAnchorCandidate(Control element)

Parameters

element Control

A control within the subtree of the IScrollAnchorProvider.

RegisterContentPresenter(ContentPresenter)

Called when an ContentPresenter is registered with the control.

protected override bool RegisterContentPresenter(ContentPresenter presenter)

Parameters

presenter ContentPresenter

The presenter.

Returns

bool

ScrollToEnd()

Scrolls to the bottom-left corner of the content.

public void ScrollToEnd()

ScrollToHome()

Scrolls to the top-left corner of the content.

public void ScrollToHome()

SetAllowAutoHide(Control, bool)

Gets the value of the AllowAutoHideProperty attached property.

public static void SetAllowAutoHide(Control control, bool value)

Parameters

control Control

The control to set the value on.

value bool

The value of the property.

SetBringIntoViewOnFocusChange(Control, bool)

Gets the value of the BringIntoViewOnFocusChange attached property.

public static void SetBringIntoViewOnFocusChange(Control control, bool value)

Parameters

control Control

The control to set the value on.

value bool

The value of the property.

SetHorizontalScrollBarVisibility(Control, ScrollBarVisibility)

Gets the value of the HorizontalScrollBarVisibility attached property.

public static void SetHorizontalScrollBarVisibility(Control control, ScrollBarVisibility value)

Parameters

control Control

The control to set the value on.

value ScrollBarVisibility

The value of the property.

SetHorizontalSnapPointsAlignment(Control, SnapPointsAlignment)

Gets the value of the HorizontalSnapPointsAlignment attached property.

public static void SetHorizontalSnapPointsAlignment(Control control, SnapPointsAlignment value)

Parameters

control Control

The control to set the value on.

value SnapPointsAlignment

The value of the property.

SetHorizontalSnapPointsType(Control, SnapPointsType)

Gets the value of the HorizontalSnapPointsType attached property.

public static void SetHorizontalSnapPointsType(Control control, SnapPointsType value)

Parameters

control Control

The control to set the value on.

value SnapPointsType

The value of the property.

SetIsDeferredScrollingEnabled(Control, bool)

Sets whether dragging of Thumb elements should update the ScrollViewer only when the user releases the mouse.

public static void SetIsDeferredScrollingEnabled(Control control, bool value)

Parameters

control Control
value bool

SetIsScrollChainingEnabled(Control, bool)

Sets the value of the IsScrollChainingEnabled attached property.

public static void SetIsScrollChainingEnabled(Control control, bool value)

Parameters

control Control

The control to set the value on.

value bool

The value of the property.

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.

SetIsScrollInertiaEnabled(Control, bool)

Sets whether scroll gestures should include inertia in their behavior and value.

public static void SetIsScrollInertiaEnabled(Control control, bool value)

Parameters

control Control
value bool

SetVerticalScrollBarVisibility(Control, ScrollBarVisibility)

Gets the value of the VerticalScrollBarVisibility attached property.

public static void SetVerticalScrollBarVisibility(Control control, ScrollBarVisibility value)

Parameters

control Control

The control to set the value on.

value ScrollBarVisibility

The value of the property.

SetVerticalSnapPointsAlignment(Control, SnapPointsAlignment)

Gets the value of the VerticalSnapPointsAlignment attached property.

public static void SetVerticalSnapPointsAlignment(Control control, SnapPointsAlignment value)

Parameters

control Control

The control to set the value on.

value SnapPointsAlignment

The value of the property.

SetVerticalSnapPointsType(Control, SnapPointsType)

Gets the value of the VerticalSnapPointsType attached property.

public static void SetVerticalSnapPointsType(Control control, SnapPointsType value)

Parameters

control Control

The control to set the value on.

value SnapPointsType

The value of the property.

UnregisterAnchorCandidate(Control)

Unregisters a control as a potential scroll anchor candidate.

public void UnregisterAnchorCandidate(Control element)

Parameters

element Control

A control within the subtree of the IScrollAnchorProvider.

Events

ScrollChanged

Occurs when changes are detected to the scroll position, extent, or viewport size.

public event EventHandler<ScrollChangedEventArgs>? ScrollChanged

Event Type

EventHandler<ScrollChangedEventArgs>