控件大小随网格大小而变化 [英] control size changes with grid size

查看:80
本文介绍了控件大小随网格大小而变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网格上有文本框和标签

并且所有这些都在wpf应用程序的窗口中。



i设置了所有位置和控件的边距,但是当我更改网格大小时,为什么控件大小会自动更改?



i不想要那个,我该怎么办?



i需要帮助..

i have text boxes and labels on grid
and all are on window in wpf application.
.
i have set all positions and margins of controls, but when i change grid size, then why control size get changes automatically ??
.
i dont want that, what should i do ??
.
i need help..

推荐答案

请看Wes Aday和我的问题的评论。



简答:你需要使用一个最重要的XAML属性值字符串:Auto。如果你有一个Height =Auto的行定义,它的实际高度将由内容的控件定义;如果你有一个Width = Auto的列定义,它的实际宽度将由控件定义。其他宽度/高度定义会给出更复杂的行为。



背景



在WPF布局中,有太相反的方法:以太内容的大小定义控制器的大小,或者大小controller定义了内容的大小(如果它适合,但它也可以缩放到任何大小)。这里,容器,我的意思是一些 Panel Grid 也是 Panel )或 Window System.Windows.Controls.ContentControl )。选择对于水平和垂直方向是独立的。



所以,整个行为还将取决于窗口属性 SizeToContent

http://msdn.microsoft.com/en-us/library/system .windows.wi ndow.sizetocontent%28v = vs.110%29.aspx [ ^ ]。



-SA
Please see the comments to the question, by Wes Aday and mine.

Short answer: you need to use one of the most practically important XAML attribute value strings: "Auto". If you have a row definition with Height="Auto", its actual height will be defined by the content's controls; if you have a column definition with Width=Auto", its actual width will be defined by controls. Other width/height definitions give more complex behavior.

Background:

In WPF layout, there are too opposite approaches: ether the size of the content defines the size of the controller, or the size of the controller defines the size of the content (if it even fit, but it also can be scaled to any size). Here, by "container", I mean some Panel (Grid is also a Panel) or Window (System.Windows.Controls.ContentControl). The choice is independent for horizontal and vertical direction.

So, the whole behavior will also depend on the Window property SizeToContent:
http://msdn.microsoft.com/en-us/library/system.windows.window.sizetocontent%28v=vs.110%29.aspx[^].

—SA


首先将固定高度和宽度赋予控件,这些控件添加了网格。不要将对齐属性设置为拉伸。
First Give the Fixed Height and Width to your Controls, which are added that grid. Do not set Alignment Properties to "Stretch" .


这篇关于控件大小随网格大小而变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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