创建自定义控件文件夹-CustControl

创建用户控件-CustButton

再改Button


<Button.Resources>
<ResourceDictionary Source="pack://application:,,,/ModuleView;component/SummaryStyle.xaml"/>
</Button.Resources>
UI
<Button.Template>
<ControlTemplate TargetType="Button">
<Grid ClipToBounds="True" MouseLeftButtonDown="Grid_MouseLeftButtonDown">
<Border Name="back" Style="{StaticResource borderStyle}" CornerRadius="6">
<ContentPresenter
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Content="{TemplateBinding Content}"/>
</Border>
<Path Fill="White" x:Name="MyPath">
<Path.Data>
<EllipseGeometry x:Name="MyEllipse" RadiusX="0" RadiusY="{Binding RelativeSource={RelativeSource Mode=Self},Path=RadiusX}"/>
</Path.Data>
</Path>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="back" Property="Visibility" Value="Visible"/>
<Setter TargetName="back" Property="Background" Value="Gray"/>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter TargetName="back" Property="Background" Value="#44FFFFFF"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
<Border>
</Border>
事件
private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
var target = Template.FindName("MyEllipse", this) as EllipseGeometry;
target.Center = Mouse.GetPosition(this);
var animation = new DoubleAnimation()
{
From = 0,
To = 150,
Duration = new Duration(TimeSpan.FromSeconds(1)),
};
target.BeginAnimation(EllipseGeometry.RadiusXProperty, animation);
var animation2 = new DoubleAnimation()
{
From = 0.3,
To = 0,
Duration = new Duration(TimeSpan.FromSeconds(1)),
};
var target2 = Template.FindName("MyPath", this) as Path;
target2.BeginAnimation(Path.OpacityProperty, animation2);
}
使用
<local:CustButton
Background="Transparent"
Grid.Column="1"
Width="80" Height="32"
FontSize="13"
Foreground="White"
Content="取消"
Command="{Binding CancelFrm}"
CommandParameter="{Binding ElementName=CreatePrj}"/>