WPF按钮实现水波纹效果

xaml代码如下

<Button x:Class="UI.btn.ZButton" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" xmlns:i="http://schemas.microsoft.com/xaml/behaviors" xmlns:btn="clr-namespace:UI.btn" d:DesignHeight="450" d:DesignWidth="800" Cursor="Hand"> <Button.Template> <ControlTemplate TargetType="Button" > <Grid ClipToBounds="True" Background="{TemplateBinding Background}" MouseLeftButtonDown="Grid_MouseLeftButtonDown" > <Border> <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Content="{TemplateBinding Content}" > </ContentPresenter> </Border> <Path Fill="Black" x:Name="MyPath"> <Path.Data> <EllipseGeometry x:Name="MyEllip" Center="{Binding MyProperty}" RadiusX="0" RadiusY="{Binding RelativeSource={RelativeSource Mode=Self},Path=RadiusX}"> </EllipseGeometry> </Path.Data> </Path> </Grid> </ControlTemplate> </Button.Template> </Button>

1|0CS代码

private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { var target=Template.FindName("MyEllip", 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); }


__EOF__

本文作者可乐加冰
本文链接https://www.cnblogs.com/zt199510/p/13224906.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   可乐_加冰  阅读(1678)  评论(2编辑  收藏  举报
编辑推荐:
· 开发中对象命名的一点思考
· .NET Core内存结构体系(Windows环境)底层原理浅谈
· C# 深度学习:对抗生成网络(GAN)训练头像生成模型
· .NET 适配 HarmonyOS 进展
· .NET 进程 stackoverflow异常后,还可以接收 TCP 连接请求吗?
阅读排行:
· 本地部署 DeepSeek:小白也能轻松搞定!
· 基于DeepSeek R1 满血版大模型的个人知识库,回答都源自对你专属文件的深度学习。
· 如何给本地部署的DeepSeek投喂数据,让他更懂你
· 在缓慢中沉淀,在挑战中重生!2024个人总结!
· 大人,时代变了! 赶快把自有业务的本地AI“模型”训练起来!
点击右上角即可分享
微信分享提示