Share via


ItemsView.TryGetItemIndex(Double, Double, Int32) Method

Definition

Retrieves the index of the closest item to a position relative to the top-left corner of the ItemsView.

public:
 virtual bool TryGetItemIndex(double horizontalViewportRatio, double verticalViewportRatio, [Out] int & index) = TryGetItemIndex;
bool TryGetItemIndex(double const& horizontalViewportRatio, double const& verticalViewportRatio, [Out] int & index);
public bool TryGetItemIndex(double horizontalViewportRatio, double verticalViewportRatio, out int index);
Public Function TryGetItemIndex (horizontalViewportRatio As Double, verticalViewportRatio As Double, ByRef index As Integer) As Boolean

Parameters

horizontalViewportRatio
Double

double

A value that determines whether an item with its left or right edge closest to the viewport ratio point is returned.

verticalViewportRatio
Double

double

A value that determines whether an item with its top or bottom edge closest to the viewport ratio point is returned.

index
Int32

int

The index of the closest item; or, -1 if the index was not found.

Returns

Boolean

bool

true if the index was found. false if the control's inner ItemsRepeater or ScrollView part is not set, or the data source's ItemsSource is empty; the index out parameter is set to -1 in those cases.

Remarks

This method returns false when the control's inner ItemsRepeater or ScrollView part is not set, or the data source's ItemsSource is empty. The index out parameter is set to -1 in those cases. Otherwise, the index is set to a value greater or equal to 0 and returns true.

The TryGetItemIndex method can be called in an ItemsView.Loaded event handler or any later time so that the inner control template parts are loaded.

The input parameters are interpreted as follows:

Argument value Effect
horizontalViewportRatio <= 0.5 Return item with left edge closest to viewport ratio point.
horizontalViewportRatio > 0.5 Return item with right edge closest to viewport ratio point.
verticalViewportRatio <= 0.5 Return item with top edge closest to viewport ratio point.
verticalViewportRatio > 0.5 Return item with bottom edge closest to viewport ratio point.

Applies to