WPF 中的 TextBlock 绑定以显示链接
我通过 Caliburn.Micro 将 TextBlock 绑定到字符串。现在我不想自动检测 URL 并将其显示为可单击的超链接。
我尝试在 ValueConverter 中将每个 URL 更改为超链接。不幸的是,我现在显示了“
我该怎么做?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您永远无法将其与
TextBlock.Text
一起使用,它始终只是纯文本。您可以绑定ContentControl
的Content
并在转换器中返回普通的TextBlock
或包含TextBlock
代码>超链接You'll never get this to work with
TextBlock.Text
, it will always be just plain text. You could bind theContent
of aContentControl
and in the converter return a normalTextBlock
or aTextBlock
containing aHyperlink
在这种情况下,您将收到您发送的内容。我假设您正在绑定到 Text 属性,这就是您获得纯文本的原因。
这并不简单。您必须提供 Inlines 属性,该属性允许您添加格式化文本(运行)和超链接。但是,这不是依赖属性,因此绑定不可用。
您可以在代码中提供此属性,或者使用某种行为以某种方式为您提供对该属性的 XAML 访问权限。
In that case, you are getting what you are sending. I assume you are binding to the Text property and that's why you are getting plain text.
This is not simple. You must feed the Inlines property which allow you to add formatted text (Run) and Hyperlinks. However this is not a dependency property so a binding is not available.
You might feed this property in code, or, use a behavior which somehow gives you XAML kind of access to that property.