如何在StackPanel上使用Border

Mic*_*zyn 0 c# wpf panel stackpanel

所以,我正在尝试在WPF中开发应用程序(再次).我希望在我周围有一个漂亮的黑色边框和圆形的corenrs StackPanel.为了做到这一点,我写了:

<Border x:Name="debugPanel" CornerRadius="10" BorderBrush="Black" BorderThickness="2" Grid.Row="5" Grid.Column="6" Grid.RowSpan="2">
    <StackPanel Grid.RowSpan="3" Background="#C7C7C7">
        <!--contents-->
    </StackPanel>
</Border>
Run Code Online (Sandbox Code Playgroud)

但结果很难看:(见下图:

在此输入图像描述

请注意,它甚至可能是添加边框的错误方式,我只是想出了自己.所以,如果你有任何建议和评论,我也很乐意听到.

Len*_*art 6

在边框上设置背景而不是StackPanel:

<Border x:Name="debugPanel" Background="#C7C7C7" CornerRadius="10" BorderBrush="Black" BorderThickness="2" Grid.Row="5" Grid.Column="6" Grid.RowSpan="2">
    <StackPanel Grid.RowSpan="3" Background="Transparent">
        <!--contents-->
    </StackPanel>
</Border>
Run Code Online (Sandbox Code Playgroud)