在页面导航之前显示ContentDialog

本文关键字:显示 ContentDialog 导航 | 更新日期: 2023-09-27 18:14:21

我正在windows phone 8.1应用程序上工作,并尝试在导航到任何页面之前显示登录对话框(一个ContentDialog)。我尝试在App.xaml.cs中添加OnLaunched方法中的代码,但对话框没有显示:

protected async override void OnLaunched(LaunchActivatedEventArgs e)
{
...
await new ContentDialog1().ShowAsync();
if (!rootFrame.Navigate(typeof(FirstPage), e.Arguments))
            {
                throw new Exception("Failed to create initial page");
            }
}

虽然如果我使用消息对话框代替,它会显示得很好。任何建议吗?

在页面导航之前显示ContentDialog

我又看了一眼,似乎你需要在显示ContentDialog之前用框架填充当前窗口。因此,您需要重新排序默认初始化代码。这在我的设置中有效:

    Protected Overrides Async Sub OnLaunched(e As LaunchActivatedEventArgs)
      Dim rootFrame As Frame = New Frame()
      Window.Current.Content = rootFrame
      Window.Current.Activate() '//'Without this the dialog is "shown" but invisible and untouchable :D
      Dim a As New ContentDialog1
      Await a.ShowAsync()
      ...
      rootFrame.Navigate(GetType(MainPage), e.Arguments)
      ...

>当用户使用hardwarebackkey或与之相关的页面历史返回到应用程序时,onlaunching '不会运行。你应该处理Window.Current。激活事件。

AddHandler Window.Current.Activated, AddressOf WindowActivated
Private Sub WindowActivated(sender As Object, e As Windows.UI.Core.WindowActivatedEventArgs)
    Select Case e.WindowActivationState
        Case Windows.UI.Core.CoreWindowActivationState.CodeActivated
            '//'TODO
        Case Windows.UI.Core.CoreWindowActivationState.Deactivated
            '//'TODO
    End Select
End Sub
PS:

你需要导航到某个地方;

如果你不这样做,有一个超时将会杀死你的应用程序。