gpt4 book ai didi

c# - 从 ContentDialog 导航到页面

转载 作者:太空宇宙 更新时间:2023-11-03 23:19:27 25 4
gpt4 key购买 nike

我有一个 ContentDialog,当我在“MyPage”界面中单击一个按钮时,该 ContentDialog 包含一个按钮“Connexion”,让我导航到“ConnexionNvPage”页面这是我的代码:

MyPage.xaml.cs:

private async void WithoutCnx_Tapped(object sender, TappedRoutedEventArgs e)
{
await new MyContentDialog().ShowAsync();

}

MyContentDialog.xaml.cs:

 private void ConxBtn_Click(object sender, RoutedEventArgs e)
{
this.Hide();
//this.Frame.Navigate(typeof(ConnexionNvPage), null);
}

MyContentDialog.xaml:

<ContentDialog
x:Class="Project.MyContentDialog"
.......
>
<Grid>
<Button Content="Connexion" x:Name="ConxBtn" Click="ConxBtn_Click" />
</Grid>
</MyContentDialog>

但我仍然无法从 ContentDialog 导航到“ConnexionNvPage”谢谢帮助

最佳答案

有两种方法可以做到这一点:

获取窗口框架而不是使用 this.Frame

(Window.Current.Content as Frame)?.Navigate(typeof(ConnexionNvPage), null);

或者获取 ContentDialog 结果而不是使用点击事件处理程序(对于简单定义主要/次要按钮并使用它们的情况很有用)

var result = await new MyContentDialog().ShowAsync();

// primary button was clicked
if (result == ContentDialogResult.Primary)
{
this.Frame.Navigate(typeof(ConnexionNvPage), null);
}

关于c# - 从 ContentDialog 导航到页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35914800/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com