WPF的按钮样式

1-设置圆角
第一种

 <Button Content="圆角按钮">
     <Button.Resources>
         <Style TargetType="{x:Type Border}">
             <Setter Property="CornerRadius" Value="8"/>
         </Style>
     </Button.Resources>
 </Button>

第二种:

 <Button Content="红色按钮" Width="110" Height="38" Style="{StaticResource Button.Red}" Margin="20,0,10,0"/>


 <Style x:Key="Button.Red" TargetType="{x:Type Button}">
        <Setter Property="Foreground" Value="White"/>
        <Setter Property="Background" Value="Red"/>
        <Setter Property="FontSize" Value="14"/>
        <Setter Property="Padding" Value="0"/>
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}" >
                    <Border x:Name="border" CornerRadius="4" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="true">
                        <ContentPresenter x:Name="contentPresenter" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Foreground" Value="White"/>
                            <Setter Property="Background" Value="Red"/>
                        </Trigger>
                        <Trigger Property="IsFocused" Value="True">
                            <Setter Property="Foreground" Value="White"/>
                            <Setter Property="Background" Value="Red"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

你可能感兴趣的:(WPF,wpf)