WPF 中的 TextBlock 绑定以显示链接

发布于 2025-01-05 11:08:54 字数 208 浏览 5 评论 0 原文

我通过 Caliburn.Micro 将 TextBlock 绑定到字符串。现在我不想自动检测 URL 并将其显示为可单击的超链接。

我尝试在 ValueConverter 中将每个 URL 更改为超链接。不幸的是,我现在显示了“”,但没有实际的链接。

我该怎么做?

I'm binding a TextBlock to a string through Caliburn.Micro. Now I wan't to automatically detect URLs and display them as a clickable hyperlink.

I've tried doing so in a ValueConverter changing every URL to a Hyperlink. Unfortunately I now have "<Hyperlink..." displayed but no actuall link.

How would I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烂人 2025-01-12 11:08:54

您永远无法将其与 TextBlock.Text 一起使用,它始终只是纯文本。您可以绑定 ContentControlContent 并在转换器中返回普通的 TextBlock 或包含 TextBlock代码>超链接

You'll never get this to work with TextBlock.Text, it will always be just plain text. You could bind the Content of a ContentControl and in the converter return a normal TextBlock or a TextBlock containing a Hyperlink

萌酱 2025-01-12 11:08:54

在这种情况下,您将收到您发送的内容。我假设您正在绑定到 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文