【问题标题】:How to Implement Hyperlink Control in windows8如何在 windows 8 中实现超链接控制
【发布时间】:2013-11-23 05:40:25
【问题描述】:

在windows 8.1中,microSoft在metro中新增了一个控件:Hyperlink,它是一个内联控件,而不是HyperlinkBut​​ton。但是不兼容windows 8。

所以,我想在 windows 8 中实现超链接。

但是内联类型没有 Tapped Event。

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

【问题讨论】:

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


    【解决方案1】:

    您应该能够通过InlineUIContainerTextBlock's Inlines 内部使用HyperlinkButton,如here

        /// <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 });
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多