在WPF表单上定位控件 [英] Positioning controls on a WPF form

查看:71
本文介绍了在WPF表单上定位控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常基本的问题要解决.
我在WPF表单上有很多控件.某些控件在网格内.当最大化和调整窗口大小时,我希望这些控件在网格内保持居中,但是当我最大化窗口时,这些控件就被扔掉了.我知道这可能与控件的Margin属性有关.有人可以告诉我如何设置边距或任何其他属性,以使控件也留在我想要的位置吗?

请先感谢

解决方案

Etienne_123写道:

某些控件位于网格内.在最大化和调整窗口大小时,我希望这些控件在网格内保持居中状态.



什么是带有控件的网格的父级?父级可能会影响布局.

下面是一个网格示例,其中控件位于窗口的中心:

<Grid HorizontalAlignment="Center" VerticalAlignment="Center" ><br />        <Grid.RowDefinitions><br />            <RowDefinition Height="*" /><br />            <RowDefinition Height="*" /><br />        </Grid.RowDefinitions><br />        <Grid.ColumnDefinitions><br />            <ColumnDefinition Width="*" /><br />            <ColumnDefinition Width="*" /><br />        </Grid.ColumnDefinitions><br />        <Button Content="button1" Grid.Column="0" Grid.Row="0" /><br />        <Button Content="button2" Grid.Column="1" Grid.Row="1" /><br />    </Grid>




I have a pretty basic question to which I want a solution.
I have a bunch of controls on a WPF form. Some controls are within a Grid. I want these controls to stay centered within the grid when maximizing and resizing the window, but as soon as I maximize my window the controls get thrown out of position. I know this probably has someting to do with the Margin property of the controls. Can someone just please tell me how to set the margin or any other property so that the controls stay where I want them too

Thanks in advance

解决方案

Etienne_123 wrote:

Some controls are within a Grid. I want these controls to stay centered within the grid when maximizing and resizing the window



What is the parent of the grid with the controls? The parent may
be affecting the layout.

Here''s an example of a grid with controls that stays centered in a window:

<Grid HorizontalAlignment="Center" VerticalAlignment="Center" ><br />        <Grid.RowDefinitions><br />            <RowDefinition Height="*" /><br />            <RowDefinition Height="*" /><br />        </Grid.RowDefinitions><br />        <Grid.ColumnDefinitions><br />            <ColumnDefinition Width="*" /><br />            <ColumnDefinition Width="*" /><br />        </Grid.ColumnDefinitions><br />        <Button Content="button1" Grid.Column="0" Grid.Row="0" /><br />        <Button Content="button2" Grid.Column="1" Grid.Row="1" /><br />    </Grid>




这篇关于在WPF表单上定位控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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