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. PyQt4(简单计算器)

    随便写写 import sys import calc from PyQt4 import QtCore, QtGui class MyWidget(QtGui.QWidget): num1 = &q ...

  2. linux(centos7)下SVN服务器搭建手札

    linux(centos)下SVN服务器如何搭建?说到SVN服务器,想必大家都知道,可以是在LINUX下如何搭建SVN服务器呢?那么今天给大家分享一下linux(centos)搭建SVN服务器的思路! ...

  3. 编译并导入OpenSSL

    编译并导入OpenSSL 1. 首先,需要运行脚本生成OpenSSL库,参考 https://github.com/x2on/OpenSSL-for-iPhone 示例 2. 运行脚本生成静态库 下一 ...

  4. Custom Settings.in 配置信息收集

    [Settings] Priority=Default Properties=MyCustomProperty [Default] ;是否允许部署操作系统到目标计算机 OSInstall=YES ;是 ...

  5. 铁乐学Python_day12_作业

    1.写函数,返回一个扑克牌列表,里面有52项,每一项是一个元组 例如:[('红心',2),('草花',2), -('黑桃','A')] def poker(): suit = ['红心', '梅花', ...

  6. 一、初识MySQL数据库 二、搭建MySQL数据库(重点) 三、使用MySQL数据库 四、认识MySQL数据库的数据类型 五、操作MySQL数据库的数据(重点)

    一.初识MySQL数据库 ###<1>数据库概述     1. 数据库         长期存储在计算机内的,由组织的可共享的数据集合         存储数据的仓库         文件 ...

  7. python第十二课——for in循环

    1.for...in循环: 有两个使用场景: 场景一:for in和range对象配合使用 range对象的引入讲解 格式:range([start,end,step]): 特点:索引满足含头不含尾的 ...

  8. [USACO19FEB]Moorio Kart

    题目 我们的神仙教练在考试里放了这道题,当时我非常惊讶啊 背包是\(O(n^3)\)的吧明明是带根号的好吧,那既然要优化的话 NTT!什么时候我们教练会在考试里放多项式了 模数\(1e9+7\)? 任 ...

  9. vux UI 项目国际化

    第一步必须装 vux vux-loader vuex 和vuex-i18n npm i vux-loader -D npm i vuex vux vuex-i18n -S 安装完成需要配置webpac ...

  10. net::ERR_CONNECTION_RESET 报错原因

    1>  向tomcat 服务器上上传视频, 谷歌浏览器控制台报出: 打开信地址栏后 发现: net::ERR_CONNECTION_RESET 错误, 但是此视频以经过mp4转码(注: 浏览器支 ...