user3821206
user3821206

Reputation: 619

navigate to a Page from the ContentDialog

I have a ContentDialog that will be shown when I click on a Button in "MyPage" interface,this ContentDialog contains a button "Connexion" that let me navigate to the "ConnexionNvPage" page this is my code:

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>

but I still can't navigate to the "ConnexionNvPage" from the ContentDialog thanks for help

Upvotes: 1

Views: 1102

Answers (1)

Igor Ralic
Igor Ralic

Reputation: 15006

Two ways you can do this:

Get the Window frame instead of using this.Frame

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

Or get the ContentDialog result instead of using the click event handler (useful for cases when you simply define the primary/secondary buttons and use those)

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

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

Upvotes: 4

Related Questions