[Beginner WPF] Control size Adaptive

Source: Internet
Author: User

Want to in win on their own little tools to write, GUI nature is unavoidable, so decided to learn WPF, direct drag control is very convenient AH. Control is dragged out and later found to change the window size at run time the control does not redraw, and a search has found a workaround: Use the Viewbox control.

The function of the Viewbox control is "defines a content decorator that can stretch and a-a single child to fill the available space", which is viewbox only can have a child element and will stretch/scale the child element to fill the available space. You can usually place controls that require a change in size in a canvas or grid or other type of control, and then place the control in Viewbox, for example:

1<Viewbox>2<Grid>3<datepicker x:name="Dateselector"Horizontalalignment="Stretch"margin="10,10,165,222"Verticalalignment="Stretch"/>4<textbox x:name="Content"Horizontalalignment="Stretch"margin="10,43"textwrapping="Wrap"text="input"Verticalalignment="Stretch"/>5<button x:name="ADD"Content="ADD"Horizontalalignment="Stretch"margin="197,228,10,10"Verticalalignment="Stretch"Width=" the"click="Add_click"/>6</Grid>7</Viewbox>

The child controls in Viewbox need to set the Horizontalaligment and VerticalAlignment properties (if not in canvas) to stretch, which represent the horizontal and vertical alignment characteristics of the child controls when they are combined in the parent control. The canvas is based on an absolutely positioned layout, so this property has no effect.

Viewbox can change the Stretch property to select how the child element fits into the Viewbox free space, and the stretch enumeration is as follows:

Fill: Resize the content to fill the target dimension without preserving the aspect ratio;

None: Content remains its original size;

Uniform: Adjusts the size of the content while preserving the original aspect ratio of the content to fit the target size. The Stretch property value in Viewbox defaults to uniform;

Adjusts the size of the content while preserving the original aspect ratio of the content to fill the target size.   If the aspect ratio of the target rectangle differs from the aspect ratio of the source rectangle, the source content is clipped to fit the target dimension;  

[Beginner WPF] Control size Adaptive

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.