ListItem.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

一个 Thickness 结构,它指定要应用的填充量(以与设备无关的像素为单位)。 默认为统一粗细,即零 (0.0)。

示例

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

<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 描述的值,后跟以下单位说明符之一: px``in

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

in 为英寸;1in==96px

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

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

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

in 为英寸;1in==96px

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

依赖项属性信息

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

适用于

另请参阅