C# WPF将Button按钮设置为圆角

首先在XAML中定义一个Button按钮

        <Button Margin="155,39,171,10" Content="圆角矩形控件" Foreground="White" Template="{StaticResource ButtonTemplate}"> </Button>

然后在上面写上如下代码

<Window.Resources>
        <ControlTemplate x:Key="ButtonTemplate" TargetType="{x:Type Button}">
            <Border x:Name="Border" BorderBrush="Blue" BorderThickness="2" CornerRadius="5" Background="Red" TextBlock.Foreground="White">  <!--设置控件的边框,圆角,背景色,字体颜色-->
                <ContentPresenter Margin="{TemplateBinding Padding}" HorizontalAlignment="Center" VerticalAlignment="Center"> <!--显示控件的内容-->
                </ContentPresenter>
            </Border>
        </ControlTemplate>
    </Window.Resources>

然后就出现了我们想要的
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_44790046/article/details/102626458