AnchoredBlock.Padding 属性

定义

获取或设置元素的填充厚度。

public:
 property System::Windows::Thickness Padding { System::Windows::Thickness get(); void set(System::Windows::Thickness value); };
public System.Windows.Thickness Padding { get; set; }
member this.Padding : System.Windows.Thickness with get, set
Public Property Padding As Thickness

属性值

一个 Thickness 结构,它指定要应用的边距量(以与设备无关的像素为单位)。

默认值为统一粗细,即零 (0.0)。

示例

以下示例演示如何设置 Padding 元素的 属性 Block (Paragraph) 。

<FlowDocument Background="LightSlateGray" ColumnWidth="2000">
  <Section Background="DarkMagenta" Margin="0" Padding="0">
    <Paragraph Background="White">
      <Run>Default paragraph.</Run>
    </Paragraph>
    <Paragraph Background="White">
      <Run>Default paragraph.</Run>
    </Paragraph>
    <Paragraph Background="LightBlue" Margin="50">
      <Run>This paragraph has a magin of 50 pixels set, but no padding.</Run>
    </Paragraph>
    <Paragraph Background="LightCoral" Padding="50">
      <Run>This paragraph has padding of 50 pixels set, but no margin.</Run>
    </Paragraph>
    <Paragraph Background="LightGreen" Margin="50" Padding="50">
      <Run>This paragraph has both padding and margin set to 50 pixels.</Run>
    </Paragraph>
    <Paragraph Background="White">
      <Run>Default paragraph.</Run>
    </Paragraph>
    <Paragraph Background="White">
      <Run>Default paragraph.</Run>
    </Paragraph>
  </Section>
</FlowDocument>

下图显示了此示例的呈现效果。 夸张的粗细和颜色用于插图。

屏幕截图:带边距和边距的段落

下面的示例演示如何以编程方式设置 Padding 属性。

FlowDocument flowDoc = new FlowDocument();
Section sec = new Section();

flowDoc.Background = Brushes.LightSlateGray;
flowDoc.ColumnWidth = 2000;
sec.Background = Brushes.DarkMagenta;
sec.Padding = sec.Margin = new Thickness(0);

Paragraph defPar1 = new Paragraph(new Run("Default paragraph."));
Paragraph defPar2 = new Paragraph(new Run("Default paragraph."));
Paragraph defPar3 = new Paragraph(new Run("Default paragraph."));
Paragraph defPar4 = new Paragraph(new Run("Default paragraph."));
defPar1.Background = defPar2.Background = defPar3.Background = defPar4.Background = Brushes.White;

Paragraph marginPar = new Paragraph(new Run("This paragraph has a magin of 50 pixels set, but no padding."));
marginPar.Background = Brushes.LightBlue;
marginPar.Margin = new Thickness(50);
Paragraph paddingPar = new Paragraph(new Run("This paragraph has padding of 50 pixels set, but no margin."));
paddingPar.Background = Brushes.LightCoral;
paddingPar.Padding = new Thickness(50);
Paragraph marginPaddingPar = new Paragraph(new Run("This paragraph has both padding and margin set to 50 pixels."));
marginPaddingPar.Background = Brushes.LightGreen;
marginPaddingPar.Padding = marginPaddingPar.Margin = new Thickness(50);

sec.Blocks.Add(defPar1);
sec.Blocks.Add(defPar2);
sec.Blocks.Add(marginPar);
sec.Blocks.Add(paddingPar);
sec.Blocks.Add(marginPaddingPar);
sec.Blocks.Add(defPar3);
sec.Blocks.Add(defPar4);
flowDoc.Blocks.Add(sec);
Dim flowDoc As New FlowDocument()
Dim sec As New Section()

flowDoc.Background = Brushes.LightSlateGray
flowDoc.ColumnWidth = 2000
sec.Background = Brushes.DarkMagenta
sec.Margin = New Thickness(0)
sec.Padding = sec.Margin

Dim defPar1 As New Paragraph(New Run("Default paragraph."))
Dim defPar2 As New Paragraph(New Run("Default paragraph."))
Dim defPar3 As New Paragraph(New Run("Default paragraph."))
Dim defPar4 As New Paragraph(New Run("Default paragraph."))
defPar4.Background = Brushes.White
defPar3.Background = defPar4.Background
defPar2.Background = defPar3.Background
defPar1.Background = defPar2.Background

Dim marginPar As New Paragraph(New Run("This paragraph has a magin of 50 pixels set, but no padding."))
marginPar.Background = Brushes.LightBlue
marginPar.Margin = New Thickness(50)
Dim paddingPar As New Paragraph(New Run("This paragraph has padding of 50 pixels set, but no margin."))
paddingPar.Background = Brushes.LightCoral
paddingPar.Padding = New Thickness(50)
Dim marginPaddingPar As New Paragraph(New Run("This paragraph has both padding and margin set to 50 pixels."))
With marginPaddingPar
    .Background = Brushes.LightGreen
    .Margin = New Thickness(50)
    .Padding = marginPaddingPar.Margin
End With

sec.Blocks.Add(defPar1)
sec.Blocks.Add(defPar2)
sec.Blocks.Add(marginPar)
sec.Blocks.Add(paddingPar)
sec.Blocks.Add(marginPaddingPar)
sec.Blocks.Add(defPar3)
sec.Blocks.Add(defPar4)
flowDoc.Blocks.Add(sec)

注解

Padding 是位于元素内容区域内的缓冲区空间,位于元素的内容和元素的内边缘之间。 与 Margin相反,后者是位于元素内容区域外部的缓冲区空间,位于元素内容区域的边缘和父元素的边缘之间。

XAML 属性用法

<object Padding="uniformThickness"/>  
- or -  
<object Padding="independentThickness"/>  
- or -  
<object Padding="qualifiedUniformThickness"/>  
- or -  
<object Padding="qualifiedIndependentThickness"/>  

XAML 值

uniformThickness
要统一应用于所有四个厚度尺寸的单个 Double 值的字符串表示形式。 例如, 的 值 "10" 等效于 的值 "10,10,10,10"。 非限定值以与设备无关的像素度量。 字符串不需要显式包含小数点。

independentThickness
四个有序 Double 值的字符串表示形式,对应于左、上、右和下的独立厚度尺寸,按此顺序排列。 四个值必须用逗号分隔:不允许使用空格。 例如,“5,10,15,20”会导致内容左侧有 5 个像素的填充,内容上方有 10 个像素的填充,内容右侧有 15 个像素的填充,内容下方有 20 个像素的填充。

qualifiedUniformThickness
uniformThickness 描述的值,后跟以下单位说明符之一: pxin

px (默认) 是与设备无关的单位, (单位) 1/96 英寸

in 为英寸;1in==96px

例如, "1in" 在所有方向上提供 1 英寸的统一填充。

qualifiedIndependentThickness
independentThickness 描述的值,每个独立值后跟以下单位说明符之一: pxin

px (默认) 是与设备无关的单位, (单位) 1/96 英寸

in 为英寸;1in==96px

例如,"1.5in,0.8in,1.5in,0.8in"。 单位说明符可以混合或省略一个或多个值。

依赖项属性信息

标识符字段 PaddingProperty
元数据属性设置为 true AffectsMeasure

适用于