Class ScrollViewer
Represents a scroll viewer. A scroll viewer element has an infinite virtual size defined by its ScrollingMode. The user can move in that virtual size by touching and panning on the screen.
[DataContract("ScrollViewer")]
[DataContractMetadataType(typeof(ScrollViewer.ScrollViewerMetadata))]
public class ScrollViewer : ContentControl, IUIElementUpdate, IUIElementChildren, IIdentifiable
- Inheritance
-
ScrollViewer
- Implements
- Inherited Members
- Extension Methods
Constructors
ScrollViewer()
public ScrollViewer()
Fields
CurrentScrollingSpeed
The current speed of the scrolling in virtual pixels.
protected Vector3 CurrentScrollingSpeed
Field Value
ScrollOffsets
The current offsets (in virtual pixels) generated by the scrolling on the Content element.
protected Vector3 ScrollOffsets
Field Value
Properties
Content
Gets or sets the content of the ContentControl.
public override UIElement Content { get; set; }
Property Value
Exceptions
- InvalidOperationException
The value passed has already a parent.
ContentAsAnchorInfo
The current content casted as IScrollAnchorInfo
protected IScrollAnchorInfo ContentAsAnchorInfo { get; }
Property Value
Remarks
ContentAsScrollInfo
The current content casted as IScrollInfo.
protected IScrollInfo ContentAsScrollInfo { get; }
Property Value
Remarks
Deceleration
The automatic deceleration of the scroll after the user remove its finger from the screen. The unit is in virtual pixels.
[DataMember]
[Display(null, "Behavior")]
public float Deceleration { get; set; }
Property Value
IsEnabled
Gets or sets a value indicating whether this element is enabled in the user interface (UI).
public override bool IsEnabled { set; }
Property Value
IsTouchedDown
Gets a value that indicates whether the is currently touched down.
protected virtual bool IsTouchedDown { get; set; }
Property Value
IsUserScrollingViewer
Indicate if the user is currently touching the scroll viewer and performing a scroll gesture with its finger.
protected bool IsUserScrollingViewer { get; }
Property Value
LastFrameTranslation
Gets the scrolling translation that occurred during the last frame
protected Vector3 LastFrameTranslation { get; }
Property Value
ScrollBarColor
Gets or sets the color of the scrolling bar.
[DataMember]
[Display(null, "Appearance")]
public Color ScrollBarColor { get; set; }
Property Value
ScrollBarThickness
Gets or sets the scrolling bar thickness in virtual pixels.
[DataMember]
[Display(null, "Appearance")]
public float ScrollBarThickness { get; set; }
Property Value
ScrollMode
The viewer allowed scrolling mode.
[DataMember]
[Display(null, "Behavior")]
public ScrollingMode ScrollMode { get; set; }
Property Value
ScrollPosition
The current scroll position (in virtual pixels) of the ScrollViewer. That is, the position of the left-top-front corner of the ScrollViewer in its Content.
public Vector3 ScrollPosition { get; }
Property Value
Remarks
If the Content of the scroll viewer implements the IScrollInfo interface,
the ScrollPosition will be
Note that ScrollPosition is valid only when IsArrangeValid is
ScrollStartThreshold
Gets or sets the threshold distance over which a touch move starts scrolling.
[DataMember]
[Display(null, "Behavior")]
public float ScrollStartThreshold { get; set; }
Property Value
SnapToAnchors
Gets or sets the value indicating if the element should snap its scrolling to anchors.
[DataMember]
[Display(null, "Behavior")]
public bool SnapToAnchors { get; set; }
Property Value
Remarks
Snapping will work only if Content implements interface IScrollAnchorInfo
TouchScrollingEnabled
Gets or sets the scrolling behavior on touches. True to allow the user to scroll by touching, false to forbid it.
[DataMember]
[Display(null, "Behavior")]
public bool TouchScrollingEnabled { get; set; }
Property Value
ViewPort
The viewport of the ScrollViewer in virtual pixels.
public Vector3 ViewPort { get; }
Property Value
Methods
ArrangeOverride(Vector3)
When overridden in a derived class, positions possible child elements and determines a size for a UIElement derived class.
protected override Vector3 ArrangeOverride(Vector3 finalSizeWithoutMargins)
Parameters
finalSizeWithoutMargins
Vector3The final area within the parent that this element should use to arrange itself and its children.
Returns
- Vector3
The actual size used.
CanScroll(Orientation)
Indicate if the scroll viewer can scroll in the given direction.
public bool CanScroll(Orientation direction)
Parameters
direction
OrientationThe direction to use for the test
Returns
- bool
true if the scroll viewer can scroll in the provided direction, or elsefalse
HideScrollBars()
protected void HideScrollBars()
InvalidateAnchorInfo()
Called by an IScrollAnchorInfo interface that attached to a ScrollViewer when the value of any anchor changed.
public void InvalidateAnchorInfo()
InvalidateScrollInfo()
Called by an IScrollInfo interface that is attached to a ScrollViewer when the value of any scrolling property size changes. Scrolling properties include offset, extent, or viewport.
public void InvalidateScrollInfo()
MeasureOverride(Vector3)
When overridden in a derived class, measures the size in layout required for possible child elements and determines a size for the UIElement-derived class.
protected override Vector3 MeasureOverride(Vector3 availableSizeWithoutMargins)
Parameters
availableSizeWithoutMargins
Vector3The available size that this element can give to child elements. Infinity can be specified as a value to indicate that the element will size to whatever content is available.
Returns
- Vector3
The size desired by the children
OnPreviewTouchDown(TouchEventArgs)
The class handler of the event PreviewTouchDown. This method can be overridden in inherited classes to perform actions common to all instances of a class.
protected override void OnPreviewTouchDown(TouchEventArgs args)
Parameters
args
TouchEventArgsThe arguments of the event
OnPreviewTouchMove(TouchEventArgs)
The class handler of the event PreviewTouchMove. This method can be overridden in inherited classes to perform actions common to all instances of a class.
protected override void OnPreviewTouchMove(TouchEventArgs args)
Parameters
args
TouchEventArgsThe arguments of the event
OnPreviewTouchUp(TouchEventArgs)
The class handler of the event PreviewTouchUp. This method can be overridden in inherited classes to perform actions common to all instances of a class.
protected override void OnPreviewTouchUp(TouchEventArgs args)
Parameters
args
TouchEventArgsThe arguments of the event
OnScrollModeChanged()
Method triggered when ScrollMode changed. Can be overridden in inherited class to change the default behavior.
protected virtual void OnScrollModeChanged()
OnTouchEnter(TouchEventArgs)
The class handler of the event TouchEnter. This method can be overridden in inherited classes to perform actions common to all instances of a class.
protected override void OnTouchEnter(TouchEventArgs args)
Parameters
args
TouchEventArgsThe arguments of the event
OnTouchLeave(TouchEventArgs)
The class handler of the event TouchLeave. This method can be overridden in inherited classes to perform actions common to all instances of a class.
protected override void OnTouchLeave(TouchEventArgs args)
Parameters
args
TouchEventArgsThe arguments of the event
OnTouchScrollingEnabledChanged()
Method triggered when TouchScrollingEnabled changed. Can be overridden in inherited class to change the default behavior.
protected virtual void OnTouchScrollingEnabledChanged()
ScrollOf(Vector3, bool)
Try to scroll of the provided scrolling translation value from the current position. If the provided translation is too important, it is clamped.
public void ScrollOf(Vector3 scrollTranslation, bool stopScrolling = true)
Parameters
scrollTranslation
Vector3The scroll translation to perform (in virtual pixels)
stopScrolling
boolIndicate if the scrolling should be stopped after the scroll action.
ScrollOfInternal(ref Vector3, bool)
public void ScrollOfInternal(ref Vector3 scrollTranslation, bool stopScrolling)
Parameters
ScrollTo(Vector3, bool)
Try to scroll to the provided position (in virtual pixels). If the provided translation is too important, it is clamped.
public void ScrollTo(Vector3 scrollAbsolutePosition, bool stopScrolling = true)
Parameters
scrollAbsolutePosition
Vector3The scroll offsets to apply
stopScrolling
boolIndicate if the scrolling should be stopped after the scroll action.
Remarks
Note that the computational cost of ScrollTo(Vector3, bool) can be greatly higher than ScrollOf(Vector3, bool) when scrolling is delegated to a Content virtualizing its items. When possible, prefer call to ScrollOf(Vector3, bool)
ScrollToBeginning(Orientation, bool)
Go to the beginning of the scroll viewer's content in the provided direction.
public void ScrollToBeginning(Orientation direction, bool stopScrolling = true)
Parameters
direction
OrientationThe direction in which to scroll
stopScrolling
boolIndicate if the scrolling should be stopped after the scroll action.
ScrollToEnd(Orientation, bool)
Go to the end of the scroll viewer's content in the provided direction.
public void ScrollToEnd(Orientation direction, bool stopScrolling = true)
Parameters
direction
OrientationThe direction in which to scroll
stopScrolling
boolIndicate if the scrolling should be stopped after the scroll action.
StopCurrentScrolling()
Stops the scrolling at the current position.
public void StopCurrentScrolling()
Update(GameTime)
Method called by Update(GameTime). This method can be overridden by inherited classes to perform time-based actions. This method is not in charge to recursively call the update on child elements, this is automatically done.
protected override void Update(GameTime time)
Parameters
time
GameTimeThe current time of the game
UpdateWorldMatrix(ref Matrix, bool)
Method called by UpdateWorldMatrix(ref Matrix, bool). Parents are in charge of recursively calling this function on their children.
protected override void UpdateWorldMatrix(ref Matrix parentWorldMatrix, bool parentWorldChanged)