1
votes

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:

enter image description here

Which is not expected. Anything I am missing here?

2

2 Answers

2
votes

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">
1
votes
  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();


}