WPF: Add canvas to flowdocument

Source: Internet
Author: User

If you add canvas to flowdocument:

<Flowdocumentscrollviewer>

<Flowdocument>

<Blockuicontainer>

<Border borderbrush = "Navy" borderthickness = "1">

<Canvas>

<Button canvas. Left = "20" canvas. Top = "40"> A </button>

</Canvas>

</Border>

</Blockuicontainer>

<Paragraph> paragraph A </Paragraph>

<Paragraph> paragraph B </Paragraph>

</Flowdocument>

</Flowdocumentscrollviewer>

 

This result is surprising. Canvas is scaled into a line, while the buttons in canvas are below. In fact, flowdocument planning is like a vertical stackpanel. For details, refer to this article: WPF: a canvas with the minimum size. As for the buttons below, they are actually the content in the canvas, except that the default attribute cliptobounds of the canvas is false. If it is set to true, the content out of the border will not be displayed.

 

Solution: You can manually set a fixed height for canvas or use the custom canvas control in the previous article:

<Flowdocument>

<Blockuicontainer>

<Border borderbrush = "Navy" borderthickness = "1">

<LOC: sizedcanvas xmlns: Loc = "CLR-namespace: mgen_wpf">

<Button canvas. Left = "20" canvas. Top = "40"> A </button>

</LOC: sizedcanvas>

</Border>

</Blockuicontainer>

<Paragraph> paragraph A </Paragraph>

<Paragraph> paragraph B </Paragraph>

</Flowdocument>

 

Result:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.