WPF Forms Adaptive Resolution

Source: Internet
Author: User

When you create a form (Window) using WPF, if you set a fixed height (height) and width (width), once the user's computer resolution is too low, the form and its contents cannot be fully displayed. To solve this problem, there are several methods to be consulted:

1, whether the form is made full screen (windowstate= "maximized"), or set a fixed form size, you can use the DockPanel control to layout. The DockPanel control has a special property: Lastchildfill= "True", which allows the last element in the control to be filled with the remaining position automatically.

For example, a page, the top is a drop-down box, the bottom is a button, the middle is a list. You can lay out as follows:

<dockpanel lastchildfill= "True" >

<combobox Height = "dockpanel.dock=" "Top"/>

<button Height = "dockpanel.dock=" "Bottom"/>

<listview dockpanel.dock= "Top" >......</ListView>

</DockPanel>

This way, even if the ListView of the list control appears to be placed in the last position of the DockPanel, it is actually populated between the drop-down box combobox and the button buttons. Because the drop-down boxes and buttons specify a specific height, the large space in the middle of the page is filled by the ListView, and you do not need to specify a specific height or width for the listview.

No matter how the resolution changes, the elements in the form can be displayed as long as the form is fully visible.

2, if the form is not full-screen, set the specific height or width, at some resolutions even the form can not be displayed completely, then the above method does not solve the problem. You can use only the Viewbox control, which stretches and scales a single child element to fill the free space.

A Viewbox can have only one child, and you need to include Viewbox as the outermost element in the form, including all the controls, such as:

<Window>

<View>

<DockPanel>

......

</DockPanel>

</View>

<Window>

Then place all the controls in the DockPanel for layout. A form that has been processed by Viewbox automatically scales the form, all controls in the form, including the font size, in a resolution that is insufficient to show the original size.

Http://www.cnblogs.com/xuxiaona/archive/2013/03/28/2987193.html

WPF Forms Adaptive Resolution

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.