wpf 如何使XAML边框与元素保持一致?

5q4ezhmt  于 2023-10-22  发布在  其他
关注(0)|答案(1)|浏览(115)

我正在制作一个C#国际象棋应用程序,我想为棋盘做一个边框,但边框和棋盘之间有很大的空间。
XAML代码:

<Grid>
   
    <Border BorderBrush="SaddleBrown" BorderThickness="2">
        <local:ChessBoard x:Name ="chessBoard"/>
    </Border>
       
</Grid>

ChessBoard元素扩展了grid,并将其HorizontalAlignmentVerticalAlignment设置为Center
它看起来是这样的:The look of the application

bd1hkmkf

bd1hkmkf1#

将以下对齐属性添加到边界

VerticalAlignment="Center" HorizontalAlignment="Center"

完整代码:

<Grid>
   
    <Border BorderBrush="SaddleBrown" BorderThickness="2" VerticalAlignment="Center" HorizontalAlignment="Center">
        <local:ChessBoard x:Name ="chessBoard"/>
    </Border>
       
</Grid>

相关问题