难以理解保证金性质
本文关键字:保证金 | 更新日期: 2023-09-27 18:14:53
MSDN描述的页边距属性,quote:
Margin属性描述了元素与其子元素(为什么不是父元素?)或同级元素之间的距离。
但是如何确定边距是否描述了元素与其子元素(父元素)或同级元素之间的距离?这里有两个例子:第一个:
<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和Grid(父)top之间的距离,并且RadioButtons应该相互重叠。这真的很棘手,到底发生了什么?
你可以把边距看作是你要应用的对象与该对象周围任何东西之间的一段距离,而不管它是父对象还是同级对象。
我不知道"技术"的定义是什么,但它总是这样工作的。
另一方面,填充是对象的边界和对象中包含的任何内容之间的距离。
StackPanel和Grid组件有不同类型的插入子组件。在这两个例子中,边距的位置根据布局变化而变化。在StackPanel中,每个孩子都是在与StackPanel属性相关的布局中的最后一个孩子之后添加的,比如从左到右,从下到上等等。在Grid中,子元素的位置必须由编码器给出,如果不是,则将每个子元素添加到布局的锚点,作为默认的左上角,以便在分配任何位置时它们相互重叠。