I load some quiz questions in one of my PivotItems .
My problem is when the user is in this PivotItem and if swipe to go to another PivotItem I want to get pop-up MessagePrompt before leaving this PivotItem to another, asking if the user really want to finish the quiz. I tried LostFocus event and Unloaded event but nothnig happens.
How can i manage this?
PS I know that the Quiz should be in another page, but I want to achieve this with pivotItems.
Subscribe to pivots selectionChanged event
Pivot_SelectionChanged Event
{
if(Pivot.selectedindex==1|| 3|| 4)
{
Messagebox();
}
}
Assuming 2 is your pivot items index.
now if the user chooses "yes" then assign pivots selectedindex to 2
You can subscribe to the SelectionChanged event whenever a PivotItem is changed. Check the link for some examples from MSDN.
I haven't tried this out yet, but I believe the PivotItem will still change even when the pop-up occurs. So once you get the pop-up and you give the user a choice to stay on the current Pivot or go to the next, you might have to change the PivotItem programatically back to the quiz Pivot.
A slightly messy way would be to preserve the currently selected Pivot Index state, and subscribe to the DragStartedGestureEventArgs using the windows phone controls toolkit.
<controls:Pivot x:Name="pivotControl" Title="MY APPLICATION">
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener DragStarted="SelectedPivotChanging"></toolkit:GestureListener>
</toolkit:GestureService.GestureListener>
<controls:PivotItem Header="item1">
<Grid />
</controls:PivotItem>
<controls:PivotItem Header="item2">
<Grid/>
</controls:PivotItem>
</controls:Pivot>
private void SelectedPivotChanging(object sender, DragStartedGestureEventArgs e)
{
if (pivotControl.SelectedIndex == 0)
{
if (MessageBox.Show("Are you sure you wish to navigate away?", "Un-Answered questions", MessageBoxButton.OKCancel)
== MessageBoxResult.Cancel)
{
//pivotControl.SelectedIndex = previousIndex;
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.