• WPF 跟随鼠标动画 by wgscd


    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;

            }

    fffffffffffffffff
    test red font.
  • 相关阅读:
    震撼!一组你从未见过的惊艳照片(45图)
    看明白了这个故事不精神分裂算你厉害
    关于无法把程序(Adobe Fireworks CS5)添加到打开方式的解决办法
    打伞
    引用视频全屏播放代码
    居家生活实用生活小窍门集锦
    《西游记第一百零一回》第一百零一回观(转)
    保鲜膜的28种妙用!
    20155324 《信息安全系统设计基础》课程总结
    2017-2018-1 20155324 《信息安全系统设计基础》第十四周学习总结
  • 原文地址:https://www.cnblogs.com/wgscd/p/4469427.html
Copyright © 2020-2023  润新知