保证金属性不会因相邻元素而塌陷 [英] Margin property doesn't collapse with adjacent elements
问题描述
Margin属性似乎没有崩溃,就像CSS margin属性一样.
The Margin property doesn't appear to collapse, like the CSS margin property does.
我要寻找的是一种简单的说法,即某种类型的控件(例如Button)应在其周围具有一定的间距,但不要太大.所谓简单",是指可以从样式资源在整个流程范围内轻松更改的内容.
What I'm looking for is an easy way of saying that a certain type of control (e.g., a Button) should have a certain amount of spacing around it, but not too much. By "easy", I mean something that can be easily changed process-wide from a style resource.
CSS的margin属性对此非常有效. WPF的margin属性存在的问题是相邻的Button最终具有双页边距,这看起来很糟糕.
CSS's margin property works perfectly for this. The problem with WPF's margin property is that adjacent Buttons end up having double margins, which looks awful.
处理此问题的标准方法是什么?我能想到的最好的解决方案是为控件"分配半边距.和容器"的填充,但这不适用于Grid容器.
What is the standard way to handle this? The best solution I can think of is to assign half-margins for "controls" and padding for "containers", but this doesn't work well with the Grid container.
-Steve
-Steve
推荐答案
史蒂夫
如果您设置按钮边距的样式,但仅设置左/上边距的样式,该怎么办? 这应该提供您想要的补偿,而不会出现其他问题. 您可能还需要为容器设置正确的/底部的填充样式,否则,应该在按钮全局"上给您均匀的间距.
What if you style the button margins, but only the left/top margin? This should provide the offsets you desire, without having the other issues. You might also need to style the right/bottom padding for containers, but otherwise, that should give you even spacing on buttons "globally".
这篇关于保证金属性不会因相邻元素而塌陷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!