Wpf 如何设置Label的子控件的属性

Wpf 如何设置Label的子控件的属性,wpf,wpf-style,Wpf,Wpf Style,我想更改作为默认标签控件子控件的边框控件的属性。我有下面的风格,除了对边框控件的更改外,其他所有内容都显示在UI中 <Style x:Key="StandardLabel" TargetType="{x:Type Label}" BasedOn="{StaticResource {x:Type Label}}"> <Setter Property="HorizontalAlignment" Value="Center" /> <Setter Prop

我想更改作为默认标签控件子控件的边框控件的属性。我有下面的风格,除了对边框控件的更改外,其他所有内容都显示在UI中

<Style x:Key="StandardLabel" TargetType="{x:Type Label}" BasedOn="{StaticResource {x:Type Label}}">
    <Setter Property="HorizontalAlignment" Value="Center" />
    <Setter Property="ContentStringFormat" Value="{}{0:0.000}"/>
    <Setter Property="Height" Value="25"/>
    <Setter Property="Margin" Value="0"/>
    <Style.Resources>
        <Style TargetType="{x:Type Border}" >
            <Setter Property="Padding" Value="3"/>
        </Style>
    </Style.Resources>
</Style>


我用它作为我尝试的基础,但它似乎对我不起作用。关于我做错了什么有什么想法吗?

如果您的默认标签与我的模板相同,则边框通过属性设置了填充,这将覆盖样式中完成的任何操作

<ControlTemplate TargetType="{x:Type Label}">
    <Border 
        BorderBrush="{TemplateBinding BorderBrush}" 
        BorderThickness="{TemplateBinding BorderThickness}"
        Background="{TemplateBinding Background}" 
        Padding="{TemplateBinding Padding}" 
        SnapsToDevicePixels="true"
        >
这将适用于
边框
具有
模板绑定
标签
属性的任何属性。其他任何内容(如果
Border
有任何未考虑的有用属性),可以使用本地隐式样式方法;我使用默认样式的副本测试了这一点,并从模板的边框中删除了
Background
属性:

<Style x:Key="LabelStyle1" TargetType="{x:Type Label}" BasedOn="{StaticResource {x:Type Label}}">
    <Style.Resources>
        <Style TargetType="Border">
            <Setter Property="Background" Value="LightSkyBlue" />
        </Style>
    </Style.Resources>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Label}">
                <Border 
                    BorderBrush="{TemplateBinding BorderBrush}" 
                    BorderThickness="{TemplateBinding BorderThickness}" 
                    Padding="{TemplateBinding Padding}" 
                    SnapsToDevicePixels="true"
                    >


请您看看……我让它变得更加混乱。感谢您的帮助。出于好奇,您如何查看默认模板?我创建了一个标签,将XAML编辑器置于设计模式,单击标签,并在“编辑模板”下选择类似“编辑副本”的内容。我现在正在打电话,但它就在那里的某个地方。
<Style x:Key="LabelStyle1" TargetType="{x:Type Label}" BasedOn="{StaticResource {x:Type Label}}">
    <Style.Resources>
        <Style TargetType="Border">
            <Setter Property="Background" Value="LightSkyBlue" />
        </Style>
    </Style.Resources>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Label}">
                <Border 
                    BorderBrush="{TemplateBinding BorderBrush}" 
                    BorderThickness="{TemplateBinding BorderThickness}" 
                    Padding="{TemplateBinding Padding}" 
                    SnapsToDevicePixels="true"
                    >