如何在windows8中实现超链接控制

时间:2013-11-22 07:05:32

标签: c# windows-8 microsoft-metro winrt-xaml windows-8.1

在Windows 8.1中,microSoft有一个新的控件在Metro:Hyperlink,而不是HyperlinkBut​​ton,它是一个内联控件。但它不兼容windows 8。

所以,我想在Windows 8中实现Hyperlink。

但是内联类型没有Tapped Event。

我想问:“如何将Tapped事件添加到Inlin类型控件中;”

1 个答案:

答案 0 :(得分:0)

您应该能够HyperlinkButton TextBlock's通过Inlines使用InlineUIContainerhere

    /// <summary>
    /// Appends a HyperlinkButton with
    /// the given text and navigate uri to the given RichTextBlock.
    /// </summary>
    /// <param name="richTextBlock">The rich text block.</param>
    /// <param name="text">The text.</param>
    /// <param name="uri">The URI.</param>
    public static void AppendLink(this RichTextBlock richTextBlock, string text, Uri uri)
    {
        Paragraph paragraph;

        if (richTextBlock.Blocks.Count == 0 ||
            (paragraph = richTextBlock.Blocks[richTextBlock.Blocks.Count - 1] as Paragraph) == null)
        {
            paragraph = new Paragraph();
            richTextBlock.Blocks.Add(paragraph);
        }

        var link =
            new HyperlinkButton
            {
                Content = text,
                NavigateUri = uri
            };

        paragraph.Inlines.Add(new InlineUIContainer { Child = link });
    }