• 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.
  • 相关阅读:
    git基本报错处理
    上传本地文件到gitee
    Pycharm Process finished with exit code -1073741819 (0xC0000005)
    linux ubuntu 安装后的配置
    Anaconda 和 jupyter notebook入门
    LaTeX公式小结--持续更新中
    markdown基本语法
    Python数据类型的整理
    linux磁盘分区与挂载
    第一章linux系统概述
  • 原文地址:https://www.cnblogs.com/wgscd/p/4469427.html
Copyright © 2020-2023  润新知