WPF圆角按钮例程

Posted snow-zhang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WPF圆角按钮例程相关的知识,希望对你有一定的参考价值。

<Window x:Class="WpfApp3.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp3"
        mc:Ignorable="d"
        Title="我的例程" Height="450" Width="800" Background="Black">
    <Window.Resources>

        <Style TargetType="Button" >
            <Setter Property="Template">
                
                <Setter.Value>
                    <ControlTemplate TargetType="Button" >
                        <Border x:Name="border" Background="SkyBlue" 
                                CornerRadius="10" Height="30" BorderBrush="Black" BorderThickness="0" SnapsToDevicePixels="True">
                            <Border.Effect>
                                <DropShadowEffect Color="Black" Direction="0" ShadowDepth="1" Opacity="1" />
                            </Border.Effect>
                        <TextBlock Text="{TemplateBinding Content}" 
                                  VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White" FontSize="16" FontFamily="黑体">
                                <TextBlock.Effect>
                                    <DropShadowEffect Color="Black" Direction="0" ShadowDepth="1" Opacity="1" />
                                </TextBlock.Effect>
                            </TextBlock>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="true">
                            <Setter Property="Background" Value="LightBlue" TargetName="border"></Setter>
                            </Trigger> 
                            <Trigger Property="IsPressed" Value="true">
                            <Setter Property="Background" Value="SkyBlue" TargetName="border"></Setter>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
           
    </Style>
    </Window.Resources>
    <Grid Background="Brown" >
        <Button Content="暂停" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Margin="445,344,0,0"></Button>
        <Button Content="添加" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75"  Margin="100,344,0,0"></Button>
        <Button Content="播放" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Margin="219,344,0,0"></Button>
        <Button Content="开始" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Margin="327,344,0,0" ></Button>
    </Grid>
</Window>

 



以上是关于WPF圆角按钮例程的主要内容,如果未能解决你的问题,请参考以下文章

wpf中把按钮变成圆角

Winform绘制圆角按钮

WPF RadioButton/ToggleButton 样式

如何创建 WPF 圆角容器?

wpf窗体设置阴影后,窗体圆角就会有阴影颜色,圆角就失效了,如何解决啊?求解

WPF 斜角border