[英]WP8 - Show MessageBox before leaving Pivotitem
I load some quiz questions in one of my PivotItems . 我在一个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. 我的问题是,当用户位于此PivotItem中时,如果要滑动到另一个PivotItem,我想在将该PivotItem留给另一个之前,先弹出MessagePrompt ,询问用户是否真的要完成测验。 I tried LostFocus event and Unloaded event but nothnig happens.
我尝试了LostFocus事件和Unloaded事件,但没有发生。
How can i manage this? 我该如何处理?
PS I know that the Quiz should be in another page, but I want to achieve this with pivotItems. 附言:我知道测验应该在另一页中,但是我想通过pivotItems实现。
Subscribe to pivots selectionChanged event 订阅枢轴selectionChanged事件
Pivot_SelectionChanged Event
{
if(Pivot.selectedindex==1|| 3|| 4)
{
Messagebox();
}
}
Assuming 2 is your pivot items index. 假设2是您的枢纽项目索引。
now if the user chooses "yes" then assign pivots selectedindex to 2 现在,如果用户选择“是”,则将数据透视表selectedindex分配给2
You can subscribe to the SelectionChanged event whenever a PivotItem is changed. 每当更改PivotItem时,您都可以订阅SelectionChanged事件。 Check the link for some examples from MSDN.
检查链接以获取MSDN中的一些示例。
http://msdn.microsoft.com/en-us/library/windowsphone/develop/microsoft.phone.controls.pivot.selectionchanged(v=vs.105).aspx http://msdn.microsoft.com/zh-CN/library/windowsphone/develop/microsoft.phone.controls.pivot.selectionchanged(v=vs.105).aspx
I haven't tried this out yet, but I believe the PivotItem will still change even when the pop-up occurs. 我还没有尝试过,但是我相信即使发生弹出窗口,PivotItem仍然会更改。 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.
因此,一旦出现弹出窗口并为用户提供了选择,使其停留在当前Pivot上或转到下一个,则可能必须以编程方式将PivotItem更改回测验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. 一种比较混乱的方法是保留当前选定的“数据透视索引”状态,并使用Windows Phone控件工具包订阅DragStartedGestureEventArgs。
<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;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.