Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading FlowDocument.xaml that is part of my solution

I created a FlowDocument.xaml in my current WPF project. What i want to do is when the user clicks a button the XAML document will be loaded in the code behind, have some data on the document modified, and then print it out. The sticking point is i don't know how load the flow document so that i can modify it.

When I do:

FileStream fs = File.Open("FlowDocument.xaml", FileMode.Open)

It says that it can't find the file. The file is part of the project and I'm guessing it gets packaged with the rest of the project when compiled.

Any help is appreciated

like image 347
MikeC Avatar asked Feb 24 '23 05:02

MikeC


1 Answers

Assuming it is configured to be a Resource, then you can load it like so:

FlowDocument doc= Application.LoadComponent(new Uri("/Path/FlowDocument.xaml", UriKind.RelativeOrAbsolute)) as FlowDocument;
like image 80
CodeNaked Avatar answered Mar 05 '23 02:03

CodeNaked