使用指定的 ControlTemplate 设置 UserControl 的填充?

Tor*_*enJ 1 c# wpf controltemplate

我最近创建了一个UserControl用于WrapPanel可视化一些数据的工具。我Padding对其应用了 a 以便在每个元素之间留出一些空间。

第一个版本如下所示:

<UserControl x:Class="IFCS.EntityOverviewPanel"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:l="clr-namespace:IFCS"
         mc:Ignorable="d"
         Padding="5, 5, 5, 5"
         d:DesignHeight="300" d:DesignWidth="300">
    <!-- Code -->
</UserControl>
Run Code Online (Sandbox Code Playgroud)

现在我只是应用了 aControlTemplate来覆盖我的Padding设置。

当前版本如下所示:

<UserControl x:Class="IFCS.EntityOverviewPanel"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:l="clr-namespace:IFCS"
         mc:Ignorable="d"
         d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Template>
        <ControlTemplate TargetType="UserControl">
            <!-- Code -->
        </ControlTemplate>
    </UserControl.Template>
</UserControl>
Run Code Online (Sandbox Code Playgroud)

我想再次申请PaddingUserControl但我尝试的一切都不起作用。我尝试应用一个Style使用

<UserControl.Style>
    <Style TargetType="{x:Type UserControl}">
        <Setter Property="Padding" Value="5, 5, 5, 5"/>
    </Style>
</UserControl.Style>
Run Code Online (Sandbox Code Playgroud)

但这没有用。在“标题”中设置Padding也不起作用。

我必须在哪里设置该Padding值才能获得与第一个版本相同的结果?

SHS*_*HSE 5

<UserControl Padding="5,5,5,5">
    <UserControl.Template>
        <ControlTemplate TargetType="UserControl">
            <ContentPresenter Margin="{TemplateBinding Padding}" />
            <!-- Code -->
        </ControlTemplate>
    </UserControl.Template>

    <!-- Content -->
</UserControl>
Run Code Online (Sandbox Code Playgroud)