资源简介
鼠标拖动时 控件滑动
截图:
核心代码:
using System; using System.Collections.Generic; using System.Linq; using System.Text; 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.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.Windows.Media.Animation; namespace FlashPrac2 { /// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } /// <summary> /// 完成缓冲效果 /// </summary> /// <param name="from">起始位置</param> /// <param name="to">目标位置</param> /// <param name="ar">加速加速度</param> /// <param name="dr">减速加速度</param> /// <param name="duration">持续时间</param> private void DoMove(DependencyProperty dp, double to, double ar, double dr, double duration) { DoubleAnimation doubleAnimation = new DoubleAnimation();//创建双精度动画对象 doubleAnimation.To = to;//设置动画的结束值 doubleAnimation.Duration = TimeSpan.FromSeconds(duration);//设置动画时间线长度 doubleAnimation.AccelerationRatio = ar;//动画加速 doubleAnimation.DecelerationRatio = dr;//动画减速 doubleAnimation.FillBehavior = FillBehavior.HoldEnd;//设置动画完成后执行的操作 grdTransfer.BeginAnimation(dp, doubleAnimation);//设置动画应用的属性并启动动画 } private double pressedX; /// <summary> /// 点击鼠标,记录鼠标单击的位置 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void grdTest_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { ////获得鼠标点击的X坐标 pressedX = e.GetPosition(cvsGround).X; } ////鼠标释放时的操作 private void grdTest_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e) { double transferLeft = Convert.ToDouble(grdTransfer.GetValue(Canvas.LeftProperty)); //btn1.Content = transferLeft.ToString(); if (transferLeft > 0) { transferLeft = 0; } if (this.Width - transferLeft > cvsGround.Width) { transferLeft = this.Width - cvsGround.Width; } ////获得鼠标释放时的位置 double releasedX = e.GetPosition(cvsGround).X; ////获得距离间隔 double interval = releasedX - pressedX; pressedX = 0; ////计算出传送带要的目标位置 double to = transferLeft interval; ////移动 //btn1.Content = transferLeft.ToString() " " to.ToString(); // btn1.Content = transferLeft.ToString() " " to.ToString(); DoMove(Canvas.LeftProperty, to, 0.1, 0.5, 0.5); } } }
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace WpfApplication1
{
///
/// App.xaml 的交互逻辑
///
public partial class App : Application
{
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2014-06-23 14:03 WpfApplication1\
目录 0 2014-06-23 14:25 WpfApplication1\WpfApplication1\
文件 935 2014-06-23 14:03 WpfApplication1\WpfApplication1.sln
文件 32256 2014-06-23 16:34 WpfApplication1\WpfApplication1.v11.suo
文件 187 2014-06-23 14:03 WpfApplication1\WpfApplication1\App.config
文件 326 2014-06-23 14:05 WpfApplication1\WpfApplication1\App.xaml
文件 342 2014-06-23 14:03 WpfApplication1\WpfApplication1\App.xaml.cs
目录 0 2014-06-23 14:03 WpfApplication1\WpfApplication1\bin\
目录 0 2014-06-23 14:05 WpfApplication1\WpfApplication1\bin\Debug\
文件 12800 2014-06-23 14:35 WpfApplication1\WpfApplication1\bin\Debug\WpfApplication1.exe
文件 187 2014-06-23 14:03 WpfApplication1\WpfApplication1\bin\Debug\WpfApplication1.exe.config
文件 36352 2014-06-23 14:35 WpfApplication1\WpfApplication1\bin\Debug\WpfApplication1.pdb
文件 22984 2014-06-24 10:55 WpfApplication1\WpfApplication1\bin\Debug\WpfApplication1.vshost.exe
文件 187 2014-06-23 14:03 WpfApplication1\WpfApplication1\bin\Debug\WpfApplication1.vshost.exe.config
文件 490 2010-03-17 22:39 WpfApplication1\WpfApplication1\bin\Debug\WpfApplication1.vshost.exe.manifest
文件 1467 2014-06-24 11:00 WpfApplication1\WpfApplication1\FlashPrac2.xaml
文件 3368 2014-06-23 14:28 WpfApplication1\WpfApplication1\FlashPrac2.xaml.cs
文件 288 2014-06-23 14:03 WpfApplication1\WpfApplication1\MainWindow.xaml
文件 661 2014-06-23 14:03 WpfApplication1\WpfApplication1\MainWindow.xaml.cs
目录 0 2014-06-23 14:03 WpfApplication1\WpfApplication1\obj\
目录 0 2014-06-23 14:35 WpfApplication1\WpfApplication1\obj\Debug\
文件 2325 2014-06-23 14:05 WpfApplication1\WpfApplication1\obj\Debug\App.g.cs
文件 2325 2014-06-23 14:05 WpfApplication1\WpfApplication1\obj\Debug\App.g.i.cs
文件 7060 2014-06-24 11:00 WpfApplication1\WpfApplication1\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
文件 1908 2014-06-23 14:35 WpfApplication1\WpfApplication1\obj\Debug\FlashPrac2.baml
文件 8598 2014-06-23 14:35 WpfApplication1\WpfApplication1\obj\Debug\FlashPrac2.g.cs
文件 8598 2014-06-23 14:35 WpfApplication1\WpfApplication1\obj\Debug\FlashPrac2.g.i.cs
文件 700 2014-06-23 14:05 WpfApplication1\WpfApplication1\obj\Debug\MainWindow.baml
文件 3024 2014-06-23 14:05 WpfApplication1\WpfApplication1\obj\Debug\MainWindow.g.cs
文件 3024 2014-06-23 14:05 WpfApplication1\WpfApplication1\obj\Debug\MainWindow.g.i.cs
文件 0 2014-06-23 14:03 WpfApplication1\WpfApplication1\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
............此处省略24个文件信息
相关资源
- 第二代Kinect WPF开发从入门到精通资料
- WPF21个优秀项目及源码
- SciChart控件破解方法见包内
- WPF开发框架
- wpf特效轮播图
- WPF做的监控程序
- wpf 图片滑动效果
- Telerik_UI_for_WPF破解版
- Telerik_UI_for_WPF_2019_1_116_Dev.msi
- WPF编程宝典2012源码和书(全)
- 深入浅出WPF刘铁猛 重新整理书签 带源
- WPF程序设计指南完整PDF高清版
- Telerik UI for WPF 2018_1_116
- 深入浅出WPF 重新整理目录,带源码
- Pro WPF 4.5 in C# Pro WPF系列第四版 英文书
- WPF学习书籍pdf《葵花宝典_WPF自学手册
- Telerik_UI_for_WPF_Documentation
- WPF编程宝典C#2012 第4版(包含源码)
- WPF编程宝典 第四版
- c# WPF 动态曲线显示
- WPF高级编程PDF
- WPF崩溃重启
- C#/WPF下的通用自动更新模块修正
- 基于WPF的USB设备浏览器
- WPF实现类似安卓,ISO的日期选择器
- WPF MVVM模式下 TreeView 右键菜单
- wpf入门第五篇 WPF with ECharts 项目源码
- wpf界面与类之间的交互
- WPF自定义MessageBox完善版 v2 (源码)
-
WPF 样式 st
yle 滑动开关 实现的效果
评论
共有 条评论