Wednesday, March 16, 2011

Get path geometry from FlowDocument object

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.

From stackoverflow
  • Can you use

    ChildVisual = VisualTreeHelper.GetChild(Visual yourVisual)

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

  • 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
    
    Dmitri Nesteruk : 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.
  • http://www.codeplex.com/StringToPathGeometry

  • 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.

0 comments:

Post a Comment