c# - 难以理解 Margin 属性

标签 c#

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/

相关文章:

c# - Selenium sendKeys 不输入所有文本

c# - 如何在 Microsoft Bot Framework LuisIntent 方法中获取原始消息文本

c# - 填充数据模板内的组合框

c# - 内部 protected 属性(property)仍然可以从不同的程序集访问

c# - ObservableCollection.Remove - 无法将 lambda 表达式转换为类型,因为它不是委托(delegate)类型

c# - 如何为 EF Core 中的单个查询设置命令超时?

c# - 如何强制 visual studio 使用小写类型生成属性(例如,字符串而不是字符串)

c# - 是否有用于 C# 的良好、高性能的 unsigned BigInteger 类型?

c# - 防止在 ObservableCollection.CollectionChanged 事件上添加新项目

c# - ASP.NET 网络 API : Perform Search on Table using HTTP GET Method and Linq to SQL Dynamically