WPF自定义圆形按钮样式

转帖链接:https://www.itsvse.com/thread-3348-1-1.html

 

 

新建Style.xaml,将一下代码填入,xmlns:local改为自己的

  1. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  2.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  3.                     xmlns:local="clr-namespace:WpfTest">
  4.     <Style x:Key="RoundedGelButton" TargetType="Button">
  5.         <Setter Property="Width" Value="100"/>
  6.         <Setter Property="Height" Value="100"/>
  7.         <Setter Property="Foreground" Value="White"/>
  8.         <Setter Property="Template">
  9.             <Setter.Value>
  10.                 <ControlTemplate TargetType="{x:Type Button}">
  11.                     <Grid>
  12.                         <Ellipse Name="GelBackground" StrokeThickness="0.5" Fill="Black">
  13.                             <Ellipse.Stroke>
  14.                                 <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
  15.                                     <GradientStop Offset="0" Color="#ff7e7e7e"></GradientStop>
  16.                                       <GradientStop Offset="1" Color="Black"></GradientStop>
  17.                                 </LinearGradientBrush>
  18.                             </Ellipse.Stroke>
  19.                         </Ellipse>
  20.                         <Ellipse Margin="15,5,15,50">
  21.                             <Ellipse.Fill>
  22.                                  <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
  23.                                     <GradientStop Offset="0" Color="#aaffffff"></GradientStop>
  24.                                       <GradientStop Offset="1" Color="Transparent"></GradientStop>
  25.                                 </LinearGradientBrush>
  26.                             </Ellipse.Fill>
  27.                         </Ellipse>
  28.                         <ContentPresenter Name="GelButtonContent" VerticalAlignment="Center" HorizontalAlignment="Center"
  29.                                           Content="{TemplateBinding Content}"/>
  30.                     </Grid>
  31.                     <ControlTemplate.Triggers>
  32.                         <Trigger Property="IsMouseOver" Value="True">
  33.                             <Setter Property="Ellipse.Fill" TargetName="GelBackground">
  34.                                 <Setter.Value>
  35.                                     <RadialGradientBrush>
  36.                                           <GradientStop Offset="0" Color="Lime"></GradientStop>
  37.                                       <GradientStop Offset="1" Color="DarkGreen"></GradientStop>
  38.                                     </RadialGradientBrush>
  39.                                 </Setter.Value>
  40.                             </Setter>
  41.                         </Trigger>
  42.                          <Trigger Property="IsPressed" Value="True">
  43.                             <Setter Property="Ellipse.Fill" TargetName="GelBackground">
  44.                                 <Setter.Value>
  45.                                     <RadialGradientBrush>
  46.                                           <GradientStop Offset="0" Color="#ffcc34"></GradientStop>
  47.                                       <GradientStop Offset="1" Color="#cc9900"></GradientStop>
  48.                                     </RadialGradientBrush>
  49.                                 </Setter.Value>
  50.                             </Setter>
  51.                         </Trigger>
  52.                     </ControlTemplate.Triggers>
  53.                 </ControlTemplate>
  54.             </Setter.Value>
  55.         </Setter>
  56.     </Style>
  57. </ResourceDictionary>

在App.xmal文件中添加此资源文件

   ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Style.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>


在界面中使用

   <Button Style="{StaticResource RoundedGelButton}" Content="Click Me!"></Button>


 

localStyle资源

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值