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. CSS 小结笔记之盒子模型

    网页标签可以看成是一个个盒子,页面设计就像垒积木一样,在网页中将盒子摆好显示出来.在浏览器中可以很清楚的去看到一个标签的盒子,具体方法如下: 打开浏览器的开发人员工具,在Elements中选中一个标签 ...

  2. tls/ssl工作原理及相关技术

    https://www.wosign dot com/faq/faq2016-0309-03.htm TLS/SSL的功能实现主要依赖于三类基本算法:散列函数 Hash.对称加密和非对称加密,其利用非 ...

  3. windows zend_guard+apache no ssl+php no Thread Safe fastcgi模式 环境配置

    最近公司要做代码加密,就采用ZEND GUARD 方式加密代码 并进行显示 此文为总结,以备自己以后查看和给需要的同学们参考 采用的php为5.3版本  由于现在加密的更改, 能支持zend guar ...

  4. linux上设置mysql编码

    linux下设置mysql编码 linux下设置mysql编码 首先查找MySql的cnf文件的位置: [root@flyHome gaoxiang]# find / -iname '*.cnf' - ...

  5. SQL SERVER中的And与Or的优先级

    数据库中有城市库表,其中有国家.省.城市. 举例:在广东省内(包含广东省本身),找出名称为“广州”的记录 首先,广东省内的条件是:ParentId = 2 Or Id =2 名称为“广州”的条件是:N ...

  6. 使用 JSONModel

    Magical Data Modelling Framework for JSON https://github.com/icanzilb/JSONModel New: In version 0.12 ...

  7. Linux 系统安装[Ubuntu]

    1.1.1. 安装Ubuntu 下载链接[Ubuntu16.04.1-64bit-Desktop版]: http://old-releases.ubuntu.com/releases/16.04.1/ ...

  8. route命令使用

    ---恢复内容开始--- 利用route命令可以实现内外网同时访问 route 命令参数: route [-f] [-p] [Command [Destination] [mask Netmask] ...

  9. python3编程的一些实用技巧1

    1.choice函数:返回一个列表,元组,字符串的随机项   :   调用时应导入random模块,如from random import choice 2.print 两个字符串, 逗号,+号进行连 ...

  10. Git学习文档——文件状态git status

    1.已经跟踪的文件有三种状态 已跟踪的文件,即被纳入版本控制的文件,又分为未修改(unmodified).已修改(modified).已暂存(staged)三种状态. 如图: 当在工作目录中新加入一个 ...