如何以编程方式在WPF中添加文本块的超链接 [英] How to add hyperlink to textblock in WPF programatically

查看:84
本文介绍了如何以编程方式在WPF中添加文本块的超链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在文本块中添加超链接控件以便我可以在文本块中添加链接

i希望以编程方式完成



我尝试了什么:



i want to add hyperlink control to textblock so that i can add a link in textblock
i want it to be done programatically

What I have tried:

private void Text(double x, double y, string text, Color color)
        {
            Hyperlink h = new Hyperlink();
            
            
            
            TextBlock textBlock = new TextBlock();
            
            textBlock.Text = text;
            
            textBlock.Foreground = new SolidColorBrush(color);
            Canvas.SetLeft(textBlock, x);
            Canvas.SetTop(textBlock, y);
            mycanvas.Children.Add(textBlock);

        }

推荐答案

将其添加到内联 [ ^ ] collection:

Add it to the Inlines[^] collection:
var h = new Hyperlink();
h.Inlines.Add(text);

var textBlock = new TextBlock();
textBlock.Inlines.Add(h);


这篇关于如何以编程方式在WPF中添加文本块的超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆