开发者

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 pr开发者_运维问答int 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


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;


This looks like it might be a path/relative path issue...just for testing purposes, try specifying the entire physical/absolute path in the File.Open statement...

You could also do

string path = Directory.GetCurrentDirectory();

to check to see what the current directory is and then make sure that the file FlowDocument.xaml is in that directory

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜