Getting flowdocument from xaml template file

I got a Xaml file that starts as follows:

<FlowDocument x:Name="flowDocument" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Drawing="clr-namespace:System.Drawing;assembly=System.Drawing" 

The current solution uses StremReader, referring to the physical path of the xaml file using flowdocument, and then parses the data in the template.

This is an invalid solution, so I need to get a flowdocument with a link to the physical path.

I would like to use an xmlns namespace or similar in my C # code and do

 string result = XamlWriter.Save(flowDocument) 

And use the result to parse.

Suggestions?

+4
source share
1 answer

If I understand correctly, do you want to get a FlowDocument from a string? You can do this with XamlReader.Parse :

 string result = XamlWriter.Save(flowDocument); FlowDocument new_doc = (FlowDocument)XamlReader.Parse(result); 

EDIT: If the XAML file is part of your project, you can mark it as EmbeddedResource and use it to download:

 Stream doc_stream = Assembly.GetExecutingAssembly() .GetManifestResourceStream("YourNamespace.YourFile.xaml"); FlowDocument doc = (FlowDocument)XamlReader.Load(doc_stream); 
+5
source

All Articles