【问题标题】:Adding hyperlink button in XAML with Visual Studio 11 (Windows 8)使用 Visual Studio 11 (Windows 8) 在 XAML 中添加超链接按钮
【发布时间】:2012-03-07 13:36:35
【问题描述】:

我需要添加一个超链接按钮,该按钮指向我用 C# 和 XAML 编写的 Metro 风格应用程序的网页。与 Silverlight 中一样,没有 NavigateURI 选项。是否有任何其他选项可以将超链接重定向到特定网页?

【问题讨论】:

    标签: c# xaml windows-8 microsoft-metro visual-studio-2012


    【解决方案1】:

    以防万一有人偶然发现: 我在 Windows 8 RTM 上使用 Visual Studio 2012 RTM 并且 NavigateURI 回来了并打开了默认的 Metro 浏览器。

    【讨论】:

      【解决方案2】:

      示例应用程序包中有一个示例可以执行此操作。

          // Launch a URI.
          private async void LaunchUriButton_Click(object sender, RoutedEventArgs e)
          {
              // Create the URI to launch from a string.
              var uri = new Uri(uriToLaunch);
      
              // Launch the URI.
              bool success = await Windows.System.Launcher.LaunchUriAsync(uri);
              if (success)
              {
                  rootPage.NotifyUser("URI launched: " + uri.AbsoluteUri, NotifyType.StatusMessage);
              }
              else
              {
                  rootPage.NotifyUser("URI launch failed.", NotifyType.ErrorMessage);
              }
          }
      

      【讨论】:

        【解决方案3】:

        我写了一篇关于在 Windows8 XAML 中连接 HyperlinkBut​​ton 以启动 Internet Explorer 的博客

        http://zubairahmed.net/?p=266

        【讨论】:

        • 您的代码与 Michael V 答案中的成功/失败处理相结合将是完美的。仍然困惑为什么他们删除了 NavigateUri。
        【解决方案4】:

        Windows.System.Launcher 具有为给定 Uri 或 StorageFile 打开相应应用程序的方法。只需将其连接到按钮的单击事件

        【讨论】:

          【解决方案5】:

          我不了解 Silverlight,但在 WPF(几乎与 SL 相同)中,我们有 TextBlock,其内联标记是超链接。

          <TextBlock>
              Some text 
              <Hyperlink 
                  NavigateUri="http://somesite.com"
                  RequestNavigate="Hyperlink_RequestNavigate">
                  some site
              </Hyperlink>
              some more text
          </TextBlock>
          

          U 说“在 silverlight 中没有 NavigateURI 选项”。没问题。

          我不知道 NavigateURI b4 的这个功能。所以我所做的是当用户单击该链接时,它会调用浏览器来打开我请求的链接。在鼠标悬停时,我将光标更改为手形,文本颜色为红色,鼠标返回默认颜色(蓝色)和光标(箭头)。

          我想你明白我的意思了。

          【讨论】:

          • 内联超链接控件在 WinRT 的消费者预览版中不可用。
          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-03-08
          • 1970-01-01
          • 2014-10-01
          • 1970-01-01
          • 2012-03-03
          相关资源
          最近更新 更多