TextBlock.Padding 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置一个值,该值指示内容区域的边界与内容 TextBlock所显示内容之间的填充空间的粗细。
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 结构,用于指定要应用的填充量(以独立于设备的像素为单位)。 默认值为 NaN。
示例
以下示例演示如何设置 Padding 元素的属性 TextBlock 。
<TextBlock
Name="textBlock"
Background="AntiqueWhite"
Foreground="Navy"
FontFamily="Century Gothic"
FontSize="12"
FontStretch="UltraExpanded"
FontStyle="Italic"
FontWeight="UltraBold"
LineHeight="Auto"
Padding="5,10,5,10"
TextAlignment="Center"
TextWrapping="Wrap"
Typography.NumeralStyle="OldStyle"
Typography.SlashedZero="True"
>
<Run Background="LightGreen">Text run 1.</Run>
<LineBreak/><Run Background="LightBlue">Text run 2.</Run>
<LineBreak/><Run Background="LightYellow">Text run 3.</Run>
</TextBlock>
以下示例演示如何以编程方式设置 Padding 属性。
TextBlock textBlock = new TextBlock(new Run("A bit of text content..."));
textBlock.Background = Brushes.AntiqueWhite;
textBlock.Foreground = Brushes.Navy;
textBlock.FontFamily = new FontFamily("Century Gothic");
textBlock.FontSize = 12;
textBlock.FontStretch = FontStretches.UltraExpanded;
textBlock.FontStyle = FontStyles.Italic;
textBlock.FontWeight = FontWeights.UltraBold;
textBlock.LineHeight = Double.NaN;
textBlock.Padding = new Thickness(5, 10, 5, 10);
textBlock.TextAlignment = TextAlignment.Center;
textBlock.TextWrapping = TextWrapping.Wrap;
textBlock.Typography.NumeralStyle = FontNumeralStyle.OldStyle;
textBlock.Typography.SlashedZero = true;
Dim textBlock As New TextBlock(New Run("A bit of text content..."))
textBlock.Background = Brushes.AntiqueWhite
textBlock.Foreground = Brushes.Navy
textBlock.FontFamily = New FontFamily("Century Gothic")
textBlock.FontSize = 12
textBlock.FontStretch = FontStretches.UltraExpanded
textBlock.FontStyle = FontStyles.Italic
textBlock.FontWeight = FontWeights.UltraBold
textBlock.LineHeight = Double.NaN
textBlock.Padding = New Thickness(5, 10, 5, 10)
textBlock.TextAlignment = TextAlignment.Center
textBlock.TextWrapping = TextWrapping.Wrap
textBlock.Typography.NumeralStyle = FontNumeralStyle.OldStyle
textBlock.Typography.SlashedZero = True
注解
Padding 可以描述为在所有方向(Padding="10")或四个不同的值,分别表示左、上、右和底部填充(Padding="5,0,10,20")。
如果指定的填充粗细超过相应的内容区域维度(例如,左右填充宽度的总和超过内容区域宽度),则填充的粗细按比例减少,不会大于相关的内容区域维度。
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 描述的值,每个独立值后跟以下单位说明符之一: pxin
px (默认值) 是独立于设备的单位(每单位 1/96 英寸)
in 为英寸;1in==96px
例如,"1.5in,0.8in,1.5in,0.8in"。 单元说明符可以混合或省略一个或多个值。
Dependency 属性信息
| 物品 | 价值 |
|---|---|
| 标识符字段 | PaddingProperty |
元数据属性设置为 true |
AffectsMeasure |