John Livermore
John Livermore

Reputation: 31313

UWP Pivot, determine which PivotItem is clicked

What methods can I use to detect which PivotItem is clicked by the user? This is in a Win10 environment and all users have mouse/keyboard.

<Pivot x:Name="settingsPivot" SelectedIndex="{x:Bind ViewModel.PivotSelectedIndex, Mode=TwoWay}">
    <PivotItem Header="General">
    </PivotItem>
    <PivotItem Header="Properties">
    </PivotItem>
    <PivotItem Header="Purchasers">
    </PivotItem>
</Pivot>

And I can get the SelectedIndex, but I don't want to rely on ordinal position to determine what action I should take.

Upvotes: 0

Views: 95

Answers (1)

Leander
Leander

Reputation: 859

You can use the SelectionChanged event of the pivot:

private void Pivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    if (e.AddedItems.Count > 0)
    {
        PivotItem selected = e.AddedItems[0] as PivotItem;
        Debug.WriteLine("selected pivotitem: " + selected.Header);
    }
}

Upvotes: 1

Related Questions