MSDN描述的边距属性,引号:
边距属性描述元素与其子元素之间的距离(为什么不是父元素?)或者同龄人。
但是,如何确定边距是否描述了元素与其子元素(父元素)或同级元素之间的距离?以下是两个例子:第一个例子:
<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>显然,在第一个示例中,边距描述了对等点( RadioButtons )之间的距离,而在第二个示例中,边距描述了RadioButtons与网格(父)顶部之间的距离,RadioButtons将相互重叠。这真的很棘手,到底怎么回事?
发布于 2011-11-17 14:31:02
您可以将边距看作是将其应用到的对象与该对象周围的任何其他对象之间的固定距离,而不管它是父对象还是对等体。
我不知道“技术”的定义是什么,但它总是这样工作的。
另一方面,填充是对象的边框与对象中包含的任何内容之间的距离。
发布于 2011-11-17 14:32:37
StackPanel和Grid组件有不同类型的插入子组件。在这两个例子中,边距的工作原理是相同的,因为位置会根据布局发生变化。在StackPanel中,每个子元素都是在布局中与StackPanel属性相关的最后一个子元素之后添加的,如左到右、从下到上等等。在Grid中,必须由编码器给出子节点的位置,如果没有将每个子节点添加到layouf的锚上,则作为默认的左上角,这样如果指定了任何位置,它们就会相互重叠。
https://stackoverflow.com/questions/8168707
复制相似问题