【发布时间】:2020-09-18 14:28:57
【问题描述】:
我有一个 string,里面有一个 xaml 代码,我想知道如何将此内容绑定到 TextBlock 或 Label 或其他控件。
我的字符串值是这样的:
<FlowDocument xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:markdig="clr-namespace:Markdig.Wpf;assembly=Markdig.Wpf" Style="{StaticResource {x:Static markdig:Styles.DocumentStyleKey}}">
<Paragraph Style="{StaticResource {x:Static markdig:Styles.Heading1StyleKey}}">
<Run Text="Changelog" />
</Paragraph>
<Paragraph>
<Run Text="All notable changes to this project will be documented in this file." />
</Paragraph>
程序返回的正是我向您展示的内容。
我希望有人可以帮助我。也许我只是不知道如何在 google 上解释我的问题
【问题讨论】:
-
为了便于搜索,您希望 xaml 动态编译(或执行或解释等)
-
好的,谢谢
-
这能回答你的问题吗? Compile/Execute XAML during program runtime
-
是的,但我想通过绑定来做到这一点
-
您可以将 xamlreader.parse 与字符串一起使用。这实际上与您自己编写的内容差不多。 docs.microsoft.com/en-us/dotnet/api/…