简体   繁体   中英

How to use HyperlinkButton to show ContentDialog page in Windows Phone 8.1

How to use HyperlinkButton to show ContentDialog page in Windows Phone 8.1.

XAML:

<HyperlinkButton NavigateUri="Login/ForgotPassword.xaml">
  <TextBlock>
     <Underline>
         <Run>Forgot Password?</Run>
     </Underline>
   </TextBlock>
</HyperlinkButton>

ForgotPassword.xaml is a ContentDialog Page which is present in View folder. By using this XAML code I am getting following windows screen on click event:

在此输入图像描述

Which is not expected. Anything I am missing here?

HyperlinkButton.NavigateUri is used by WebView:

The action of opening the NavigateUri in a default browser is a system action that takes place without requiring any event handling. If your intent is that the HyperlinkButton should load a specified URI within a WebView control that's also part of your app, then don't specify a value for NavigateUri. Handle the Click event instead, and call WebView.Navigate, specifying the URI to load.

If you want to navigate to a page in your app or show dialog, use Click event :

private void HyperlinkButton_Click(object sender, RoutedEventArgs e)
{
    // navigation to Page:
    this.Frame.Navigate(typeof(ForgotPassword));
    // if you need to show a dialog (it must be defined somewhere in your page clas), then make the whole event async
    ForgotPassword dialog = new ForgotPassword();    
    await dialog.ShowAsync();
 }

In XAML:

<HyperlinkButton Click="HyperlinkButton_Click">
  private void HyperlinkButton_Click(object sender, RoutedEventArgs e)
 {


ContentDialog testDialog = new ContentDialog()
{
    Title = "Testing",
    Content = "We are still testing this contentDialog",
    PrimaryButtonText = "Ok"
};

await testDialog.ShowAsync();


}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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