Class ScrollViewer
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
BringIntoViewOnFocusChangeProperty
Defines the BringIntoViewOnFocusChange property.
public static readonly AttachedProperty<bool> BringIntoViewOnFocusChangeProperty
Field Value
ExtentProperty
Defines the Extent property.
public static readonly DirectProperty<ScrollViewer, Size> ExtentProperty
Field Value
HorizontalScrollBarVisibilityProperty
Defines the HorizontalScrollBarVisibility property.
public static readonly AttachedProperty<ScrollBarVisibility> HorizontalScrollBarVisibilityProperty
Field Value
HorizontalSnapPointsAlignmentProperty
Defines the HorizontalSnapPointsAlignment property.
public static readonly AttachedProperty<SnapPointsAlignment> HorizontalSnapPointsAlignmentProperty
Field Value
HorizontalSnapPointsTypeProperty
Defines the HorizontalSnapPointsType property.
public static readonly AttachedProperty<SnapPointsType> HorizontalSnapPointsTypeProperty
Field Value
IsDeferredScrollingEnabledProperty
Defines the IsDeferredScrollingEnabled property.
public static readonly AttachedProperty<bool> IsDeferredScrollingEnabledProperty
Field Value
IsExpandedProperty
Defines the IsExpanded property.
public static readonly DirectProperty<ScrollViewer, bool> IsExpandedProperty
Field Value
IsScrollChainingEnabledProperty
Defines the IsScrollChainingEnabled property.
public static readonly AttachedProperty<bool> IsScrollChainingEnabledProperty
Field Value
IsScrollInertiaEnabledProperty
Defines the IsScrollInertiaEnabled property.
public static readonly AttachedProperty<bool> IsScrollInertiaEnabledProperty
Field Value
LargeChangeProperty
Defines the LargeChange property.
public static readonly DirectProperty<ScrollViewer, Size> LargeChangeProperty
Field Value
OffsetProperty
Defines the Offset property.
public static readonly StyledProperty<Vector> OffsetProperty
Field Value
ScrollBarMaximumProperty
Defines the ScrollBarMaximum property.
public static readonly DirectProperty<ScrollViewer, Vector> ScrollBarMaximumProperty
Field Value
ScrollChangedEvent
Defines the ScrollChanged event.
public static readonly RoutedEvent<ScrollChangedEventArgs> ScrollChangedEvent
Field Value
SmallChangeProperty
Defines the SmallChange property.
public static readonly DirectProperty<ScrollViewer, Size> SmallChangeProperty
Field Value
VerticalScrollBarVisibilityProperty
Defines the VerticalScrollBarVisibility property.
public static readonly AttachedProperty<ScrollBarVisibility> VerticalScrollBarVisibilityProperty
Field Value
VerticalSnapPointsAlignmentProperty
Defines the VerticalSnapPointsAlignment property.
public static readonly AttachedProperty<SnapPointsAlignment> VerticalSnapPointsAlignmentProperty
Field Value
VerticalSnapPointsTypeProperty
Defines the VerticalSnapPointsType property.
public static readonly AttachedProperty<SnapPointsType> VerticalSnapPointsTypeProperty
Field Value
ViewportProperty
Defines the Viewport property.
public static readonly DirectProperty<ScrollViewer, Size> ViewportProperty
Field Value
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
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
CanVerticallyScroll
Gets a value indicating whether the viewer can scroll vertically.
protected bool CanVerticallyScroll { get; }
Property Value
CurrentAnchor
The currently chosen anchor element to use for scroll anchoring.
public Control? CurrentAnchor { get; }
Property Value
Extent
Gets the extent of the scrollable content.
public Size Extent { get; }
Property Value
HorizontalScrollBarVisibility
Gets or sets the horizontal scrollbar visibility.
public ScrollBarVisibility HorizontalScrollBarVisibility { get; set; }
Property Value
HorizontalSnapPointsAlignment
Gets or sets how the existing snap points are horizontally aligned versus the initial viewport.
public SnapPointsAlignment HorizontalSnapPointsAlignment { get; set; }
Property Value
HorizontalSnapPointsType
Gets or sets how scroll gesture reacts to the snap points along the horizontal axis.
public SnapPointsType HorizontalSnapPointsType { get; set; }
Property Value
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
IsExpanded
Gets a value that indicates whether any scrollbar is expanded.
public bool IsExpanded { get; }
Property Value
IsScrollChainingEnabled
Gets or sets if scroll chaining is enabled. The default value is true.
public bool IsScrollChainingEnabled { get; set; }
Property Value
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
LargeChange
Gets the large (page) change value for the scroll viewer.
public Size LargeChange { get; }
Property Value
Offset
Gets or sets the current scroll offset.
public Vector Offset { get; set; }
Property Value
ScrollBarMaximum
public Vector ScrollBarMaximum { get; }
Property Value
SmallChange
Gets the small (line) change value for the scroll viewer.
public Size SmallChange { get; }
Property Value
VerticalScrollBarVisibility
Gets or sets the vertical scrollbar visibility.
public ScrollBarVisibility VerticalScrollBarVisibility { get; set; }
Property Value
VerticalSnapPointsAlignment
Gets or sets how the existing snap points are vertically aligned versus the initial viewport.
public SnapPointsAlignment VerticalSnapPointsAlignment { get; set; }
Property Value
VerticalSnapPointsType
Gets or sets how scroll gesture reacts to the snap points along the vertical axis.
public SnapPointsType VerticalSnapPointsType { get; set; }
Property Value
Viewport
Gets the size of the viewport on the scrollable content.
public Size Viewport { get; }
Property Value
Methods
GetAllowAutoHide(Control)
Gets the value of the AllowAutoHideProperty attached property.
public static bool GetAllowAutoHide(Control control)
Parameters
control
ControlThe 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
ControlThe 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
ControlThe 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
ControlThe 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
ControlThe 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
GetIsScrollChainingEnabled(Control)
Gets the value of the IsScrollChainingEnabled attached property.
public static bool GetIsScrollChainingEnabled(Control control)
Parameters
control
ControlThe 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
GetVerticalScrollBarVisibility(Control)
Gets the value of the VerticalScrollBarVisibility attached property.
public static ScrollBarVisibility GetVerticalScrollBarVisibility(Control control)
Parameters
control
ControlThe 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
ControlThe 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
ControlThe 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
TemplateAppliedEventArgsThe 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
GotFocusEventArgsThe event args.
OnKeyDown(KeyEventArgs)
Called before the KeyDown event occurs.
protected override void OnKeyDown(KeyEventArgs e)
Parameters
e
KeyEventArgsThe event args.
OnPropertyChanged(AvaloniaPropertyChangedEventArgs)
Called when a avalonia property changes on the object.
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
Parameters
change
AvaloniaPropertyChangedEventArgsThe 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
ScrollChangedEventArgsThe 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
ControlA 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
ContentPresenterThe presenter.
Returns
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
SetBringIntoViewOnFocusChange(Control, bool)
Gets the value of the BringIntoViewOnFocusChange attached property.
public static void SetBringIntoViewOnFocusChange(Control control, bool value)
Parameters
SetHorizontalScrollBarVisibility(Control, ScrollBarVisibility)
Gets the value of the HorizontalScrollBarVisibility attached property.
public static void SetHorizontalScrollBarVisibility(Control control, ScrollBarVisibility value)
Parameters
control
ControlThe control to set the value on.
value
ScrollBarVisibilityThe 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
ControlThe control to set the value on.
value
SnapPointsAlignmentThe 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
ControlThe control to set the value on.
value
SnapPointsTypeThe 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
SetIsScrollChainingEnabled(Control, bool)
Sets the value of the IsScrollChainingEnabled attached property.
public static void SetIsScrollChainingEnabled(Control control, bool value)
Parameters
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
SetVerticalScrollBarVisibility(Control, ScrollBarVisibility)
Gets the value of the VerticalScrollBarVisibility attached property.
public static void SetVerticalScrollBarVisibility(Control control, ScrollBarVisibility value)
Parameters
control
ControlThe control to set the value on.
value
ScrollBarVisibilityThe 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
ControlThe control to set the value on.
value
SnapPointsAlignmentThe 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
ControlThe control to set the value on.
value
SnapPointsTypeThe value of the property.
UnregisterAnchorCandidate(Control)
Unregisters a control as a potential scroll anchor candidate.
public void UnregisterAnchorCandidate(Control element)
Parameters
element
ControlA 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