MSDN 描述的边距属性,引用:
The Margin property describes the distance between an element and its child (why not parent?) or peers.
但是如何确定边距是否描述了元素与其子(父)或对等元素之间的距离?这里有两个例子: 第一个:
<GroupBox Header="Experience" Height="200" Name="yearsExperience" Width="200">
<StackPanel Margin="0,0,0,0" >
<RadioButton Content="Up to 1 year" Height="16" Name="novice" Width="120" Margin="0, 10, 0, 0" />
<RadioButton Content="1 to 4 years" Height="16" Name="intermediate" Width="120" Margin="0, 20, 0, 0" />
<RadioButton Content="5 to 9 years" Height="16" Name="experienced" Width="120" Margin="0, 20, 0, 0" />
<RadioButton Content="10 or more" Height="16" Name="accomplished" Width="120" Margin="0, 20, 0, 0" />
</StackPanel>
</GroupBox>
第二个:
<GroupBox Header="Experience" Height="200" Name="yearsExperience" Width="200">
<Grid Margin="0,0,0,0" >
<RadioButton Content="Up to 1 year" Height="16" Name="novice" Width="120" Margin="0, 10, 0, 0" />
<RadioButton Content="1 to 4 years" Height="16" Name="intermediate" Width="120" Margin="0, 20, 0, 0" />
<RadioButton Content="5 to 9 years" Height="16" Name="experienced" Width="120" Margin="0, 20, 0, 0" />
<RadioButton Content="10 or more" Height="16" Name="accomplished" Width="120" Margin="0, 20, 0, 0" />
</Grid>
</GroupBox>
显然在第一个例子中,margin 描述了对等点(RadioButtons)之间的距离,而在第二个例子中,margin 描述了 RadioButtons 和 Grid(parent)top 之间的距离,并且 RadioButtons 应该相互重叠。这真的很棘手,那么到底发生了什么?
最佳答案
您可以将边距视为应用它的对象与该对象周围的任何其他对象之间的设定距离,无论它是父对象还是对等对象。
我不知道“技术”的定义是什么,但它总是如此。
另一方面,填充是对象边界与对象内包含的任何内容之间的距离。
关于c# - 难以理解 Margin 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8168707/