locked
Absolute child element positioning in FlowDocument RRS feed

  • Question

  • Hi, WPF Team!

    I would like to know is there any way in FlowDocument to create block or inline element with absolute positioning relative to its parent, e.g. like in HTML.

    There is already exists Figure element, but it affects other blocks in document.

    Best regards,

    Karlen

    Friday, June 24, 2011 3:39 PM

Answers

  • Hi Karlen,

    I am afraid there is not such a feature in FlowDocument currently. Figure and Floater derive from AnchoredBlock Class could help you attach Block elements to flow content, but they don't use absolute coordinates neither.

    Consider we need to resize the FlowDocumentScrollViewer to fit the screen, the whole content of FlowDocument would re-layout itself. There would be no guarentee for adjusting elements using absolute coordinates which fall away from the viewport. Perhaps the FixedDocument is suitable for this case.

    Or maybe you would be interested in Annonations

    http://msdn.microsoft.com/en-us/library/ms748864.aspx 

    the anchored element would not affect other elements.

    Hope this helps

     


    Yves Zhang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, June 29, 2011 9:56 AM

All replies

  • Can you elaborate on how exactly you want it to look and appear in code?
    You could arrange it in a BlockUIContainer, there you can set it up like in regulare XAML. 

     

        <FlowDocumentScrollViewer>
          <FlowDocument>
            <BlockUIContainer>
              <Border CornerRadius="15" 
                  BorderThickness="1"
                  BorderBrush="SteelBlue">
                
                <Label Content="Welcome"/>
                
              </Border>
            </BlockUIContainer>
          </FlowDocument>
        </FlowDocumentScrollViewer>
    



    Developing is part of being a developer.
    Friday, June 24, 2011 5:27 PM
  • Hi, SharpAspirant!
    I want the element to appear just like with CSS property Position (fixed, ralative, absolute).
    For example, with Canvas control we can set element position with Canvas.Top, Canvas.Left, Canvas.Right and Canvas.Bottom properties for element, but there is no such functionality in FlowDocument and related classes.
    In web browsers our text layout wouldn't be affected and the specified DIV or SPAN would be shifted.
    For example, I'd like to have this XAML markup:
     
    <FlowDocumentScrollViewer>
     <FlowDocument>
     <Paragraph>
      <Run>Some text.</Run>
      <Span Top="-10" Left="20">Some other text, but shifted...</Span>
     </Paragraph>
     </FlowDocument>
    </FlowDocumentScrollViewer>
    

    Best regards,

    Karlen





    Friday, June 24, 2011 5:58 PM
  • Hi Karlen,

    I am afraid there is not such a feature in FlowDocument currently. Figure and Floater derive from AnchoredBlock Class could help you attach Block elements to flow content, but they don't use absolute coordinates neither.

    Consider we need to resize the FlowDocumentScrollViewer to fit the screen, the whole content of FlowDocument would re-layout itself. There would be no guarentee for adjusting elements using absolute coordinates which fall away from the viewport. Perhaps the FixedDocument is suitable for this case.

    Or maybe you would be interested in Annonations

    http://msdn.microsoft.com/en-us/library/ms748864.aspx 

    the anchored element would not affect other elements.

    Hope this helps

     


    Yves Zhang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, June 29, 2011 9:56 AM
  • Hi, Yves!

    Thanks for your reply!

    Now it is clear, why FlowDocument doesn't have such functionality. FixedDocument in my case isn't suitable. But the Annonations are very useful, so now I'am actively explore possible usage of them.

    At this time I think it is one of the known solutions.

     

    Best regards,

    Karlen

    Thursday, June 30, 2011 3:52 PM