【问题标题】:How to use HyperlinkButton to show ContentDialog page in Windows Phone 8.1如何使用 HyperlinkBut​​ton 在 Windows Phone 8.1 中显示 ContentDialog 页面
【发布时间】:2015-02-03 19:00:01
【问题描述】:

如何在 Windows Phone 8.1 中使用HyperlinkButton 显示ContentDialog 页面。

XAML:

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

ForgotPassword.xaml 是一个ContentDialog 页面,位于View 文件夹中。 通过使用此 XAML 代码,我在点击事件时得到以下窗口屏幕:

这是意料之外的。我在这里缺少什么吗?

【问题讨论】:

    标签: c# xaml windows-phone-8.1


    【解决方案1】:

    HyperlinkButton.NavigateUri被WebView使用:

    在默认浏览器中打开 NavigateUri 的操作是系统操作,无需任何事件处理即可发生。如果您的意图是 HyperlinkBut​​ton 应在 WebView 控件中加载指定的 URI,该控件也是您的应用程序的一部分,则不要为 NavigateUri 指定值。改为处理 Click 事件,并调用 WebView.Navigate,指定要加载的 URI。

    如果您想导航到应用中的页面或显示对话框,请使用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();
     }
    

    在 XAML 中:

    <HyperlinkButton Click="HyperlinkButton_Click">
    

    【讨论】:

    • ForgotPasswordContentDialog,如何显示为对话框?
    • 知道了,很好的答案,谢谢。您可以在答案中添加以下几行以完成:ForgotPassword dialog = new ForgotPassword(); await dialog.ShowAsync();
    • @AnkushMadankar 请注意,您可以将 dilog 添加到 XAML 中的页面:&lt;local:ForgotPassword x:Name="dialog"/&gt;,然后无需在代码中定义它。
    【解决方案2】:
      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();
    
    
    }
    

    【讨论】:

    • 是的。谢谢兄弟。
    猜你喜欢
    • 2014-08-13
    • 2016-02-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-24
    • 2015-03-29
    • 2014-06-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多