Add hyperlink to textblock wpf
Add hyperlink to textblock wpf
Displaying is rather simple, the navigation is another question. XAML goes like this:
<TextBlock Name="TextBlockWithHyperlink">
Some text
<Hyperlink
NavigateUri="http://somesite.com"
RequestNavigate="Hyperlink_RequestNavigate">
some site
</Hyperlink>
some more text
</TextBlock>
And the event handler that launches default browser to navigate to your hyperlink would be:
private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e) {
System.Diagnostics.Process.Start(e.Uri.ToString());
}
Edit: To do it with the text you've got from database you'll have to parse the text somehow. Once you know the textual parts and hyperlinked parts, you can build textblock contents dynamically in the code:
TextBlockWithHyperlink.Inlines.Clear();
TextBlockWithHyperlink.Inlines.Add("Some text ");
Hyperlink hyperLink = new Hyperlink() {
NavigateUri = new Uri("http://somesite.com")
};
hyperLink.Inlines.Add("some site");
hyperLink.RequestNavigate += Hyperlink_RequestNavigate;
TextBlockWithHyperlink.Inlines.Add(hyperLink);
TextBlockWithHyperlink.Inlines.Add(" Some more text");
Add hyperlink to textblock wpf的更多相关文章
- How to add hyperlink in JLabel
You can do this using a JLabel, but an alternative would be to style a JButton. That way, you don't ...
- WPF/Silverlight中的RichTextBox总结
WPF/Silverlight中的RichTextBox总结 在WPF或者是在Silverlight中有个非常强大的可以编辑的容器控件RichTextBox,有的时间会采取该控件来作为编辑控件.鉴 ...
- WPF RichTextBox相关总结
由于公司涉及到聊天对话框的功能,就想到了RichTextBox,查阅相关资料,总结下: 一.RichTextBox的内容相关的类 1.1RichTextBox的内容结构 RichTexBox是个可编辑 ...
- WPF,Silverlight与XAML读书笔记第四十三 - 多媒体支持之文本与文档
说明:本系列基本上是<WPF揭秘>的读书笔记.在结构安排与文章内容上参照<WPF揭秘>的编排,对内容进行了总结并加入一些个人理解. Glyphs对象(WPF,Silverlig ...
- WPF学习05:2D绘图 使用Transform进行控件变形
在WPF学习04:2D绘图 使用Shape绘基本图形中,我们了解了如何绘制基本的图形. 这一次,我们进一步,研究如何将图形变形. 例子 一个三角形,经Transform形成组合图形: XAML代码: ...
- 《WPF程序设计指南》读书笔记——第9章 路由输入事件
1.使用路由事件 路由事件是一种可以针对元素树中的多个侦听器(而不是仅针对引发该事件的对象)调用处理程序的事件.通俗地说,路由事件会在可视树(逻辑树是其子集)上,上下routed,如果哪个节点上订阅了 ...
- WPF笔记(1.2 Navigation导航)——Hello,WPF!
原文:WPF笔记(1.2 Navigation导航)--Hello,WPF! 这一节是讲导航的.看了一遍,发现多不能实现,因为版本更新了,所以很多旧的语法不支持了,比如说,不再有NavigationA ...
- WPF里ItemsControl的分组实现 --listbox 实现分组
我们在用到ItemsControl时,有时会用到分组,如ListBox,ListView,DataGrid.WPF的ItemsControl可以实现分组,是依托于GroupStyle,以ListBox ...
- WPF里ItemsControl的分组实现
我们在用到ItemsControl时,有时会用到分组,如ListBox,ListView,DataGrid.WPF的ItemsControl可以实现分组,是依托于GroupStyle,以ListBox ...
随机推荐
- Vue路由参数
vue路由参数 1.参数router-link vue.prototype.xxx = {add:fn}`所有组件中,使用this.xxx就能拿到这个对象2.查询字符串 (1)配置: :to=&quo ...
- c#NPOI导出2007版本excel
2003和2007版本区别: HSSFWorkbook(2003) IWorkbook(2007版本) 写完之后会有个问题,导出会报错[流已关闭]. NPOI生产.xlsx文件件时,在使用book.W ...
- 如何在SAP Kyma的控制台里扩展新的UI
方法是创建一个新的resource,类型为ClusterMicroFrontend. 使用命令行kubectl get ClusterMicroFrontend查看这些UI扩展: 最后自定义的UI出现 ...
- ubuntu下使用libsvm
matlab上的代码已经八八九九了,因为涉及到GUI和网络编程的东西,所以不得已开始学python并在python上做完整版. 下面是如何在linux和python下使用libsvm 在你的pytho ...
- CentOS linux7 设置开机启动服务
常用命令 描述 旧命令 新命令 使服务自动启动 chkconfig --level 3 http on syste ...
- Python学习记录8-继承2
继承 单继承和多继承 单继承:每个类只能继承一个类 多继承:每个类允许继承多个类 >>> class A(): pass >>> class B(A): pass ...
- 爬虫的新模块pyppeteer的使用
安装 python3 -m pip install pyppeteer 最好是py3.5+ 手动安装 你懂的,天朝网络环境很复杂,如果要用pyppeteer自己绑定的chromium,半天都下载不下来 ...
- 多线程 multiprocessing 的几个小例子
1.Pipe import multiprocessing as multip,time from multiprocessing import Process,Pipe,Event,Conditio ...
- replace函数实现
##replace函数,跟split函数处理类似,比split简单 #coding=gbk ss='** *axx* *bv** *ctt** **dff***' print(ss) result=[ ...
- hive中使用spark执行引擎的常用参数
set hive.execution.engine=spark;set hive.exec.parallel=true;set hive.exec.parallel.thread.number=8;s ...