none
Calulating Relative position in a Flow Document RRS feed

  • Question

  •  

    I am trying to save flow documents to XPS file and was successfullly able to do that. But I want to know the relative page position of text in WPF table. Is it possible to find it in WPF or can I get the table height as I dont see any height property for Table. Any help would be appreciated.

     

    Thanks

    Banu

    Friday, August 24, 2007 2:35 AM

Answers

  • FlowDocument’s content is represented as TextElements and Table is one of them. TextElement itself is represented by a pair of TextPointers (ContentStart and ContentEnd).

     

    TextPointer provides GetCharacterRect method which can return position relative to the current page.
    But the operation performed by this method depends on a valid layout, and will work only for formatted pages (visible in FlowDocumentPageViewer). Otherwise you will get Rect.Empy.

    So try calling Table.ContentStart.GetCharacterRect(LogicalDirection.Forward). It should return the correct value if Table.ContentStart.HasValidLayout returns true.

    If for some reason you are not getting expected result (I’m not 100% sure that it works for Table), try doing following:

     

    Code Snippet

    TextPointer pointer = table.ContentStart.GetNextInsertionPosition(LogicalDirection.Forward);
    if (pointer.HasValidLayout)
    {
     rect = pointer.GetCharacterRect(LogicalDirection.Forward);
    }

     

     

    Thursday, September 6, 2007 6:10 PM
    Moderator