C#WPF如何以编程方式设置控件的位置,宽度和高度? [英] C# WPF how to set location,width and height of the controls programmatically?

查看:637
本文介绍了C#WPF如何以编程方式设置控件的位置,宽度和高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做我的第一个WPF应用程序.我有一个问题,当我的窗体最大化或全屏显示时,我的控件将不会调整大小,而是停留在相同的位置.只有形式被最大化.

I'm doing my first WPF application. im having problem whereby when my form is maximized or fullscreen, my controls wont resize and just stay in the same location. only the form is maximized.

在winform中,我可以在.cs中进行如下调整:

in winform, I can do the adjustment in the .cs like the following:

panel6.Width
panel6.Height
panel6.Location

如果我的表单最大化,这将帮助我进行设置.我通过使用一些算术来做到这一点,在这些算术中,我获得了屏幕的分辨率,并进行了一些计算并获得了值,并将其设置为宽度,高度和位置. 但是这是在WINFORM中.

this will help me set it if my form is maximized. I do it by using some arithmetics where I get the resolution of screen and some calculation and get the value and can set it to the width, height and location. BUT THIS IS IN WINFORM.

我将如何解决此问题以实现WPF的最大化和全屏显示?有没有办法以编程方式通过.cs文件来完成?还是WPF带有易于解决的内置控件来解决此问题?

how will I tackle this issue for maximized and fullscreen in WPF? is there a way to be done through the .cs file programmatically? or does WPF come with a easy built in control to tackle this issue?

假设在此示例中,我在WPF中使用了停靠面板.

suppose for this example I'm using dockpanel in the WPF.

如果窗口最大化但其他控件仍然存在,那将毫无意义.

it will be pointless if window is maximized but the other controls remains.

推荐答案

设置宽度高度:

dockpanel1.width = 230;
dockpanel1.height = 230;

关于位置,wpf使用保证金:

dockpanel1.Margin = new Thickness(0,440,836,40);

这篇关于C#WPF如何以编程方式设置控件的位置,宽度和高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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