WPF自定义圆形按钮样式资源文件

 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 Source="Sytle.xaml"/>

在界面中使用

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

原文地址:https://www.cnblogs.com/saodiseng2015/p/5805877.html