Search code examples
c#wpfpanelstackpanel

How to use Border on StackPanel


So, I am trying to develop app in WPF (again). I wanted to have nice, black border with rounded corenrs around my StackPanel. In order to do this I have written:

<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>

But the result is ugly :( See below picture:

enter image description here

Note that it even might be wrong way of adding a border, I just figured it out myself. So if you have any recommendations and remarks, I would gladly hear them out as well.


Solution

  • Set the background on the border instead of the 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>