views:

251

answers:

2

What is the best way to get back the XAML/XML value of a FlowDocument?

I noticed there isn't a .Value, .Text, .Caption, .ToXml(), etc...

UDPATE:
I'd like to be able to get access to it initially to serialize to disk or database. Treat it as its own document format. Later translating it to other formats would be nice.
Also been wondering:
Any equivalent to a hyperlink (opens in new browser window) in a FlowDocument? Any workaround?

A: 

How about using XamlWriter?

Paul Betts
If you use a XamlWriter you'll get a XAML without any databinding. If you need to modify a flowdocument using it for example like a template, you can get any elements using the methods FindName or FindResources or enumerating the Blocks.Please specify to be clear for what purpose you need to get a XAML source of the flowdocument, serialize/save, modify or print?
Shurup
Shurup - see update
tyndall
+2  A: 

In response to your first question, you can use the XamlWriter to get XAML as a string. For example:

XamlWriter.Save(flowDocument);

David Veeneman has a nice example of this in the FlowDocumentToXamlConverter implementation he created for his Bindable WPF RichTextBox.

His converter will also convert back from a string containing XAML to a FlowDocument, which should handle your persistence requirement.

On your second question, you can embed WPF's Hyperlink element in a FlowDocument. These StackOverflow questions have more details:

  1. Handle links in a FlowDocument
  2. How can I get a FlowDocument Hyperlink to launch a browser

Tip: You should split your questions apart to get faster and better responses on StackOverflow. It prevents "oh, just one more thing..." fatigue!

dthrasher