tags:

views:

769

answers:

4

Can someone tell me how to get path geometry from a WPF FlowDocument object? Please not that I do not want to use FormattedText. Thanks.

A: 

Can you use

ChildVisual = VisualTreeHelper.GetChild(Visual yourVisual)

Dunno if you can take a Visual and turn it into a path geometry..

Cory R. King
+1  A: 

Get the Text property of a TextRange object initialized over the entire FlowDocument:

FlowDocument myFlowDocument = new FlowDocument();  //get your FlowDocument

//put in some (or it already has) text
string inText = "Hello, WPF World!";
TextRange tr = new TextRange(FlowDocument.ContentStart, FlowDocument.ContentEnd);
tr.Text = inText;

//get the current text out of the FlowDocument
TextRange trPrime = new TextRange(FlowDocument.ContentStart, FlowDocument.ContentEnd);
string outText = trPrime.Text;

//now outText == "Hello, WPF World!";

//to get formatting, looks like you would use myFlowDocument.TextEffects
Tim Erickson
This doesn't seem to be exactly what we're after. I'd like Path information, not just text. I'm not interested in using FormattedText as a converter.
Dmitri Nesteruk
A: 

A FlowDocument can be viewed in any number of ways, but a Path is a fixed shape. I think maybe you really want some simplified, visual-only form of a FlowDocument's contents.

In that case you might try converting the FlowDocument to an XPS FixedDocument - the FixedPages have Canvases containing a bunch of Paths and Glyphs.

Robert Macnee