我正在使用Windows Phone 8.1应用,并尝试在导航到任何页面之前显示登录对话框(ContentDialog)。我尝试在OnLaunched
中的App.xaml.cs
方法中添加代码,但对话框并没有显示出来:
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");
}
}
虽然如果我使用消息对话框,它会显示得很好。有什么建议吗?
答案 0 :(得分:1)
我再看一下,看起来你需要在显示ContentDialog之前用Frame填充当前窗口。因此,您需要稍微重新排序默认初始化代码。这适用于我的设置:
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)
...
答案 1 :(得分:0)
' App.OnLaunched'当用户使用hardwarebackkey或与其关联的页面历史记录返回到您的应用程序时,不会运行。你应该处理' Window.Current.Activated'事件
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:
你需要在某处导航;也许是一个空白的页面。
如果您没有超时,则会终止您的应用。