gpt4 book ai didi

wpf - 按钮 ControlTemplate 和圆角

转载 作者:行者123 更新时间:2023-12-04 19:46:24 31 4
gpt4 key购买 nike

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

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

最佳答案

尝试以下方法:

<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>

关于wpf - 按钮 ControlTemplate 和圆角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2594065/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com