WP8 - 在离开透视项之前显示消息框
本文关键字:显示 消息 离开 透视 WP8 | 更新日期: 2023-09-27 18:34:33
我在我的一个透视项目中加载了一些测验问题。
我的问题是当用户在此数据透视项中时,如果滑动以转到另一个数据透视项,我想在将此数据透视项留给另一个数据透视项之前弹出消息提示,询问用户是否真的要完成测验。我尝试了LostFocus事件和卸载事件,但没有发生。
我该如何管理?
附言我知道测验应该在另一个页面中,但我想通过透视项来实现这一点。
订阅透视选择更改的事件
Pivot_SelectionChanged Event
{
if(Pivot.selectedindex==1|| 3|| 4)
{
Messagebox();
}
}
假设 2 是透视项索引。
现在,如果用户选择"是",则将 Pivots selectedIndex 分配给 2
只要更改了数据透视项,就可以订阅 SelectionChanged 事件。查看链接以获取来自 MSDN 的一些示例。
http://msdn.microsoft.com/en-us/library/windowsphone/develop/microsoft.phone.controls.pivot.selectionchanged(v=vs.105(.aspx
我还没有尝试过这个,但我相信即使出现弹出窗口,数据透视项仍然会改变。因此,一旦你获得弹出窗口,并且你让用户可以选择留在当前透视上或转到下一个透视,你可能必须以编程方式将数据透视项更改回测验透视。
一种稍微混乱的方法是保留当前选定的 Pivot Index 状态,并使用 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;
}
}
}