简体   繁体   中英

Border on stackpanel inside grid cell

I am trying to apply rounded corners to a Stackpanel that is located inside a grid cell. I'm using a tag with CornerRadius. Instead of having the border surround the stackpanel, it instead stretches to surround the parent grid cell. Like this:

截图

I use the following XAML:

<Border Grid.Row="0" Grid.Column="1" BorderBrush="#FF252A30" CornerRadius="5,5,5,5" BorderThickness="2,2,2,2">
    <StackPanel Grid.Row="0" Grid.Column="1" x:Name="stackpanelContactlist" Height="336" Margin="0,113,43,113" Background="#FF252A30" d:LayoutOverrides="Width">

        Content of Stackpanel       

    </StackPanel></Border></Grid>

I'm quite new to WPF, so I'm betting it's something simple - Anyone have any suggestions on how to fix this, so the rounded borded gets applied to the child stackpanel instead of the parent grid cell?

Thanks on advance.

Just move the margin attribute ( Margin="0,113,43,113" ) from StackPanel to the border.

Also you can remove Grid.Row="0" Grid.Column="1" from the stack panel as these are not needed there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM