Control.Padding Control.Padding Control.Padding Control.Padding Property

定义

获取或设置控件内部的填充边距。Gets or sets the padding inside a control.

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

属性值

Control 的内容与其 MarginBorder 之间的空间量。The amount of space between the content of a Control and its Margin or Border. 默认情况下,所有四个边的宽度为 0。The default is a thickness of 0 on all four sides.

示例

下面的示例演示如何设置控件的填充属性。The following example shows how to set the padding property of a control.

<Button Name="btn11" Padding = "5" 
        Click="ChangePadding" TabIndex="1">
  Padding
</Button>
void ChangePadding(object sender, RoutedEventArgs e)
{
    if (btn11.Padding.Left == 5.0)
    {
        btn11.Padding = new Thickness(2.0);
        btn11.Content = "Control Padding changes from 5 to 2.";

    }
    else
    {
        btn11.Padding = new Thickness(5.0);
        btn11.Content = "Padding";
    }
}
Private Sub ChangePadding(ByVal Sender As Object, ByVal e As RoutedEventArgs)

    If (btn11.Padding.Left = 5.0) Then
        btn11.Padding = New Thickness(2.0)
        btn11.Content = "Control Padding changes from 5 to 2."
    Else
        btn11.Padding = New Thickness(5.0)
        btn11.Content = "Padding"
    End If

End Sub

注解

填充顺序按左、上、右和下顺序指定。Padding is specified in the order Left, Top, Right, and Bottom. 有关详细信息, 请Thickness参阅和对齐方式、边距和填充概述For more information, see Thickness and Alignment, Margins, and Padding Overview.

此属性仅影响其模板使用Padding属性作为参数的控件。This property only affects a control whose template uses the Padding property as a parameter. 在其他控件上, 此属性不会有任何影响。On other controls, this property has no impact.

依赖项属性信息Dependency Property Information

标识符字段Identifier field PaddingProperty
元数据属性设置为trueMetadata properties set to true AffectsParentMeasure

适用于