如何使窗口适合WPF中的任何屏幕分辨率? [英] How to fit Window to any screen resolution in WPF ?

查看:132
本文介绍了如何使窗口适合WPF中的任何屏幕分辨率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在WPF中开发了Windows应用程序。创建exe我安装在另一台计算机后它工作正常。但是当我安装在YAN(投影仪)中时,按钮文本设计在我的计算机中出现时显示不正确。



当我更改投影机页面的分辨率时看起来很小而且没有对齐。请帮助我。

I have developed windows application in WPF. After creating exe i installed in another computer it is working fine. But when i installed in YAN(projector) the buttons text design is not appearing properly as it is coming in my computer.

when i changed the resolution in projector Page is looking small and not aligned. please help me.

推荐答案

使用水平对齐和垂直对齐属性来对齐WPF窗口内的控件。并使用Margin为控件设置填充。
Use Horizontal Alignment & Vertical Alignment properties to align controls inside WPF windows. And use Margin to set padding for controls.


Horizo​​ntal Alignment属性用于水平对齐控件。它有4个选项。

1.左边

2.中心

3.正确

4.拉伸



如上所述,垂直对齐属性用于垂直对齐控件。它还有4个选项。

1.顶部

2.中心

3.底部

4.拉伸



保证金属性,用于指定左,上,右,下角的控件距离。上面的属性对于在WPF窗口中放置控件非常重要。



我将用小例子来解释这个。考虑窗口内的按钮。

Horizontal Alignment Property is used to align controls horizontally. It has 4 options.
1. Left
2. Center
3. Right
4. Stretch

Like above, Vertical Alignment Property is used to align controls vertically. It also has 4 options.
1. Top
2. Center
3. Bottom
4. Stretch

Margin property used to specify the distance for the control from Left, Top, Right, Bottom corners. The above properties are very important in placing controls in a WPF window.

I'll explain this with small example. Consider a button inside the window.
<Button Content="Button" Height="Auto" Width="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="150,140,150,140"/>



这里,Horizo​​ntalAlignment设置为Stretch,这意味着,当调整窗口大小时,按钮将被拉伸以适合。这与VerticalAlignment属性相同。



保证金:左= 150,顶部= 140,右= 150,底部= 140 - 这些边距值将按钮放置140像素距离从顶部和底部,也将按钮放置在距左和右150像素的距离。



现在,如果您调整屏幕大小,按钮将根据边距放置,并且按钮将被拉伸以适合窗口。


Here, HorizontalAlignment is set to Stretch, it means, the button will be stretched to fit when the window is resized. This is same for VerticalAlignment property.

Margin: Left = 150, Top = 140, Right = 150, Bottom = 140 - these margin values placing the button 140 pixel distance from Top and Bottom, also places the button 150 pixel distance from Left and Right.

Now if your resizes the screen, the button will be placed according to the margin, and the button wil be stretched to fit the window.


如果你在另一个窗口中托管你的wpf应用程序,你的主窗口在不同的文件中,然后将数据包装在其中使用viewbox with Stretch属性等于Fill。

整个数据将根据窗口大小进行包装。
if you are hosting your wpf app inside another window that is your main window is in different file then to wrap data inside it use viewbox with Stretch property equal to "Fill".
the whole data will wrapped according to size of window.


这篇关于如何使窗口适合WPF中的任何屏幕分辨率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆