【发布时间】:2022-01-08 22:02:01
【问题描述】:
我正在尝试传递一个包含超链接的 textBlock。像这样的:
string textblock = "<TextBlock>Hello<Hyperlink NavigateUri="https://google.com"RequestNavigate="Hyperlink_RequestNavigate">Click</Hyperlink></TextBlock>"
我想在不使用对象实例的情况下将该字符串传递到网格中。我阅读了有关 xaml 阅读器、加载器的信息,但我无法弄清楚...
我的 xaml 看起来像这样:
<Window x:Class="DailyText.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="any" Height="450" Width="800" >
<Grid>
</Grid>
</Window>
【问题讨论】:
-
即使使用 XamlParser 也会创建一个对象,您必须将其添加到 Grid 的 Children 集合中。您应该简单地创建一个 TextBlock 并为其内联分配一个超链接。
-
谢谢。但是你知道我应该如何将 XamlParser 创建的对象添加到网格的 Children 集合中?
标签: c# wpf data-binding