WPF 跟随鼠标动画 by wgscd

<UserControl x:Class="WpfApplication1.Spark"

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"

x:Name="ctl" d:DesignHeight="60" d:DesignWidth="60">

<UserControl.Resources>

<Duration  x:Key="duration">0:0:0.8</Duration>

<Storyboard x:Key="sb1" x:Name="sb1" Completed="Storyboard_Completed">

<DoubleAnimation  From="1" To="0" Duration="0:0:0.8" Storyboard.TargetName="t1" Storyboard.TargetProperty="ScaleX"></DoubleAnimation>

<DoubleAnimation  From="1" To="0" Duration="0:0:0.8" Storyboard.TargetName="t1" Storyboard.TargetProperty="ScaleY"></DoubleAnimation>

<DoubleAnimation  From="0" To="-20" Duration="0:0:0.8" Storyboard.TargetName="t2" Storyboard.TargetProperty="X"></DoubleAnimation>

<DoubleAnimation  From="1" To="0" Duration="0:0:0.8" Storyboard.TargetName="ctl" Storyboard.TargetProperty="Opacity"></DoubleAnimation>

</Storyboard>

</UserControl.Resources>

<Grid>

<Ellipse Fill="White" RenderTransformOrigin="0.5,0.5">

<Ellipse.RenderTransform>

<TransformGroup>

<ScaleTransform x:Name="t1" ScaleX="1" ScaleY="1"/>

<SkewTransform/>

<RotateTransform Angle="0"/>

<TranslateTransform x:Name="t2"  Y="0" X="0"/>

</TransformGroup>

</Ellipse.RenderTransform>

</Ellipse>

</Grid>

</UserControl>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes; namespace WpfApplication1
{
/// <summary>
/// Spark.xaml 的交互逻辑
/// </summary>
public partial class Spark : UserControl
{
public Spark()
{
InitializeComponent();
this.Width = this.Height = rnd.Next(23, 80); }
Random rnd = new Random();
public Spark(Point p)
{
InitializeComponent();
this.Width = this.Height = rnd.Next(23,80);
Canvas.SetLeft(this,p.X);
Canvas.SetTop(this,p.Y);
(Resources["sb1"] as Storyboard).Begin(); } private void Storyboard_Completed(object sender, EventArgs e)
{
try
{
(Parent as Canvas).Children.Remove(this); //GC.Collect();
} catch { } } }
}

  

 

<Window x:Class="WpfApplication1.MainWindow"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

Title="MainWindow" Height="384" Width="631">

<Grid>

<Canvas x:Name="myCanvas" Background="#FF61C1F7" ManipulationDelta="myCanvas_ManipulationDelta" MouseMove="myCanvas_MouseMove"></Canvas>

</Grid>

</Window>

------------------------------------------------------------​

private void myCanvas_MouseMove(object sender, MouseEventArgs e)

{

myCanvas.Children.Add(new Spark(e.GetPosition(myCanvas)));

//  myCanvas.Children.Add(new Spark());

Title = "" + myCanvas.Children.Count;

}

WPF 跟随鼠标动画 by wgscd的更多相关文章

  1. html5跟随鼠标炫酷网站引导页动画特效

    html5跟随鼠标炫酷网站引导页动画特效一款非常不错的引导页,文字效果渐变,鼠标跟随出绚丽的条纹.html5炫酷网站引导页,鼠标跟随出特效. 体验效果:http://hovertree.com/tex ...

  2. 关于wpf中popup跟随鼠标移动显示

    最近在做一个画图工具,里面有一个功能是需要实现,当鼠标移动的时候在,鼠标的旁边显示坐标信息. 第一反应是想到了tooltip,但是tooltip有许多的限制,查询资料的过程中看到了popup,popu ...

  3. 【翻译】使用CSS3和jQuery制作跟随鼠标方位的Hover特效

    今天我们来学习如何通过CSS3的特性和jQuery来创建一个感知鼠标滑动方向的hover效果.当鼠标滑进的时候,遮罩层会从上次鼠标滑出的方向滑入,当鼠标滑出的时候,遮罩层会跟随鼠标,从鼠标滑出的方向滑 ...

  4. canvas实现跟随鼠标旋转的箭头

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta ht ...

  5. Canvas跟随鼠标炫彩小球

    跟随鼠标炫彩小球 canvas没有让我失望,真的很有意思 实现效果 超级炫酷 实现原理 创建小球 给小球添加随机颜色,随机半径 鼠标移动通过实例化,新增小球 通过调用给原型新增的方法,来实现小球的动画 ...

  6. WPF中的动画——(三)时间线(TimeLine)

    WPF中的动画——(三)时间线(TimeLine) 时间线(TimeLine)表示时间段. 它提供的属性可以让控制该时间段的长度.开始时间.重复次数.该时间段内时间进度的快慢等等.在WPF中内置了如下 ...

  7. JS打造的跟随鼠标移动的酷炫拓扑图案

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  8. Adobe Edge Animate –获取鼠标位置及跟随鼠标功能实现

    Adobe Edge Animate –获取鼠标位置及跟随鼠标功能实现 版权声明: 本文版权属于 北京联友天下科技发展有限公司. 转载的时候请注明版权和原文地址. 在网络上浏览有关Edge相关问题的时 ...

  9. WIN32进阶必备:跟随鼠标移动的子窗口

    上两张Demo的图,方便朋友们选择是否继续看文章. 在子窗口的白色区域按下鼠标左键不放并移动鼠标可以拖拽子窗口跟随鼠标移动. 选择继续看下去的朋友不要担心,接下来就是正文了. PART 1:Demo功 ...

随机推荐

  1. 离线安装SharePoint2016

    离线安装SharePoint2016的过程中,遇到了不少问题,该文章将安装过程尽量详细描述,供自己后续参考,请不要嫌文章啰嗦哈. 本人使用的是Windows Server 2012 R2 Standa ...

  2. leetCode题解之旋转数字

    1.题目描述 X is a good number if after rotating each digit individually by 180 degrees, we get a valid n ...

  3. linux克隆机器

    首先你要先点击你的虚拟机点击克隆: 然后执行这个 vim /etc/sysconfig/network-scripts/ifcfg-eth0 去这里修改这两行 然后注释了 然后再执行这个 > / ...

  4. NSOperation的使用细节 [2]

    NSOperation的使用细节 [2] 这一节我们来写自定义nonconcurrent的operation,自定义nonconcurrent的operation很简单,重写main方法,之后处理好c ...

  5. Linux wget命令详解

    wget是一个下载文件的工具,它用在命令行下.对于Linux用户是必不可少的工具,我们经常要下载一些软件或从远程服务器恢复备份到本地服务器. wget支持HTTP,HTTPS和FTP协议,可以使用HT ...

  6. Mycat问题总结

    Mycat问题总结 一丶自增主键设置 Mycat提供了几种设置自增主键的方式 本地文件方式 数据库方式 服务器时间戳方式 分布式ZK-ID生成器 第一种和第二种只适合单点设置,对于集群不适用.第四种方 ...

  7. 内置数据结构(tuple)

    一.元组(tuple) 元组不能增.删和改,所以元组的元素只能查. tp = tuple()  #初始化一个元组 tp = () #同上 tp = (1, 2, 3, 4,) #错误的定义元组方式 t ...

  8. elif 相当于else&if

    if  条件: 语句块 elif 条件: 语句块 ... else                      #elif好像要有一个else作为结尾

  9. 利用Jquey.hover来实现 鼠标移入出现删除按钮,鼠标移出删除消失

    Html代码 <div class="box"><div class="bmbox" onclick="$('.box:first' ...

  10. 最新版本2018.1.1webstorm安装、汉化、破解教程

    一.安装(下载与激活) 1.官网下载安装包https://www.jetbrains.com/webstorm/ 2.开始安装 3.选择安装目录,点击下一步 4.勾选64位,点击下一步 5.继续下一步 ...