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. 使用Github的高级搜索功能

    使用Github的高级搜索功能 1. 首先,提供Github高级搜索帮助页面 https://help.github.com/categories/search/ 2. 搜索语法 https://he ...

  2. [翻译] TransitionKit

    TransitionKit https://github.com/blakewatters/TransitionKit A simple, elegantly designed block based ...

  3. 使用FastCoder写缓存单例

    使用FastCoder写缓存单例 FastCoder可以存储字典,数组,鄙人将FastCoder封装,CoreData可以缓存的东西,用这个都可以缓存,但是只适合缓存少量的数据(不适合存储几万条数据) ...

  4. mysql的表和约束操作

    在创建表是默认为加上数据引擎和字符集,如创建一个student表,代码如下: create table students(id int unsigned zerofill auto_increment ...

  5. Hello World ! 第一篇随笔

    Hello World ! 第一篇随笔 /* * Language: C++ * Code Name: Hello World ! * @author Metak */ #include <io ...

  6. C++项目第五次作业之文件的读取

    前言 乍看题目,用文件读取数据,这不是很简单的事嘛ps:以前写单个.cpp就是用freopen读取数据,然而当开始写的时候就出现了问题(什么叫做实力作死,有一种痛叫too young too simp ...

  7. java 扁平化输出json所有节点key/value

    本章主要介绍用java实现扁平化输出json所有节点key/value(包含所有内层子节点) 1.json结构 目的输出bill_list下的datalist里的子节点key/value 2.实现代码 ...

  8. BZ4326 运输计划

    Time Limit: 30 Sec Memory Limit: 128 MB Submit: 2132 Solved: 1372 Description 公元 2044 年,人类进入了宇宙纪元.L ...

  9. Centos7配置samba

    Centos7配置samba 1.安装 yum install samba samba-client samba-common -y 2.配置 备份已有配置mv /etc/samba/smb.conf ...

  10. python面试题库——1Python基础篇

    第一部分 Python基础篇(80题) 为什么学习Python? 语言本身简洁,优美,功能超级强大,跨平台,从桌面应用,web开发,自动化测试运维,爬虫,人工智能,大数据处理都能做 Python和Ja ...