繁体   English   中英

WP8-在离开数据透视表之前显示MessageBox

[英]WP8 - Show MessageBox before leaving Pivotitem

我在一个PivotItems中加载了一些测验问题。

我的问题是,当用户位于此PivotItem中时,如果要滑动到另一个PivotItem,我想在将该PivotItem留给另一个之前,先弹出MessagePrompt ,询问用户是否真的要完成测验。 我尝试了LostFocus事件和Unloaded事件,但没有发生。

我该如何处理?

附言:我知道测验应该在另一页中,但是我想通过pivotItems实现。

订阅枢轴selectionChanged事件

Pivot_SelectionChanged Event
{
if(Pivot.selectedindex==1|| 3|| 4)
{
Messagebox();
}
}

假设2是您的枢纽项目索引。

现在,如果用户选择“是”,则将数据透视表selectedindex分配给2

每当更改PivotItem时,您都可以订阅SelectionChanged事件。 检查链接以获取MSDN中的一些示例。

http://msdn.microsoft.com/zh-CN/library/windowsphone/develop/microsoft.phone.controls.pivot.selectionchanged(v=vs.105).aspx

我还没有尝试过,但是我相信即使发生弹出窗口,PivotItem仍然会更改。 因此,一旦出现弹出窗口并为用户提供了选择,使其停留在当前Pivot上或转到下一个,则可能必须以编程方式将PivotItem更改回测验Pivot。

一种比较混乱的方法是保留当前选定的“数据透视索引”状态,并使用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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM