0

I have a string with a xaml code inside and I want to know how can I bind this content to a control like TextBlock or Label or other.

My string value is like this :

<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>

The program is returning exactly what I show you.

I hope some one can help me. Perhaps I just don't know how to explain my problem on google

  • For searchability, you want to have xaml that is _compiled dynamically_ (or _executed_ or _interpreted_ etc..) – Pac0 Sep 18 '20 at 14:32
  • Yeah exact, thanks you – Justin Vuffray Sep 18 '20 at 14:32
  • Does this answer your question? [Compile/Execute XAML during program runtime](https://stackoverflow.com/questions/15003183/compile-execute-xaml-during-program-runtime) – Pac0 Sep 18 '20 at 14:33
  • Yeah but I want to do this with the binding – Justin Vuffray Sep 18 '20 at 14:45
  • You can use xamlreader.parse with a string. Which interally does pretty much what you've written yourself. https://learn.microsoft.com/en-us/dotnet/api/system.windows.markup.xamlreader.parse?view=netcore-3.1 – Andy Sep 18 '20 at 15:27

1 Answers1

0

I convert my string to Stream

        byte[] byteArray = Encoding.ASCII.GetBytes(ChangelogContent);
        MemoryStream stream = new MemoryStream(byteArray);
        scrollView.Content = XamlReader.Load(stream);