按钮 ControlTemplate 和圆角 [英] Button ControlTemplate and rounded corners

查看:17
本文介绍了按钮 ControlTemplate 和圆角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个按钮控制模板.我想制作带有圆角的按钮.我该怎么做?

I have a controltemplate for buttons. I want to make the buttons with rounded corners. How should I do this?

我尝试将 CornerRadius 用于边框中的按钮,但它不起作用.按钮的背景已设置为具有角边框的图像,并且按钮看起来很尴尬,因为我无法为按钮设置角.

I tried CornerRadius for button in the Border but it doesn't work. The background of the button has set to an image that has corner borders and the button looks akward as I can't set the corners for the button.

推荐答案

尝试以下操作:

<Style x:Key="GlassButton" TargetType="{x:Type Button}">
    <Setter Property="FontSize" Value="42" />
    <Setter Property="Foreground" Value="White" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Button}">
                <Border x:Name="border"
                        CornerRadius="25"
                        BorderThickness="4"
                        Background="#AA000000"
                        BorderBrush="Red"
                        RenderTransformOrigin="0.5,0.5">
                    <ContentPresenter x:Name="ButtonContentPresenter"
                                      VerticalAlignment="Center"
                                      HorizontalAlignment="Center" />
                </Border>

                <ControlTemplate.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter TargetName="border" Property="BorderBrush" Value="#FF4788c8" />
                        <Setter Property="Foreground" Value="#FF4788c8" />
                    </Trigger>
                    <Trigger Property="IsPressed" Value="True">
                        <Setter Property="Background">
                            <Setter.Value>
                                <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                    <GradientStop Color="#FFFFD190" Offset="0.35" />
                                    <GradientStop Color="Orange" Offset="0.95" />
                                    <GradientStop Color="#FFFFD190" Offset="1" />
                                </LinearGradientBrush>
                            </Setter.Value>
                        </Setter>
                        <Setter TargetName="content" Property="RenderTransform">
                            <Setter.Value>
                                <TranslateTransform Y="1.0" />
                            </Setter.Value>
                        </Setter>
                    </Trigger>
                    <Trigger Property="IsDefaulted" Value="True">
                        <Setter TargetName="border" Property="BorderBrush" Value="#FF282828" />
                    </Trigger>
                    <Trigger Property="IsFocused" Value="True">
                        <Setter TargetName="border" Property="BorderBrush" Value="#FF282828" />
                    </Trigger>
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter TargetName="border" Property="Opacity" Value="0.7" />
                        <Setter Property="Foreground" Value="Gray" />
                    </Trigger>

                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

这篇关于按钮 ControlTemplate 和圆角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆