wpf实现仿苹果水平滑动效果
来源:互联网 发布:治风湿病专科医院知乎 编辑:程序博客网 时间:2024/04/27 21:30
cs文件源码:
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{ /// /// MainWindow.xaml 的交互逻辑 /// public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } /// /// 完成缓冲效果 /// /// 起始位置 /// 目标位置 /// 加速加速度 /// 减速加速度 /// 持续时间 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; /// /// 点击鼠标,记录鼠标单击的位置 /// /// /// 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); } }}
xaml文件源码
<Window x:Class="FlashPrac2.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"Title="MainWindow" Height="350" Width="525"><Canvas Width="1500" x:Name="cvsGround"><StackPanel Width="1500" Height="525" x:Name="grdTransfer" Canvas.Left="0"Background="SkyBlue" PreviewMouseLeftButtonDown="grdTest_PreviewMouseLeftButtonDown"PreviewMouseLeftButtonUp="grdTest_PreviewMouseLeftButtonUp" Orientation="Horizontal"><Button Width="300" Height="525" x:Name="btn1" Background="SkyBlue" /><Button Width="300" Height="525" x:Name="btn2" Background="Orange" /><Button Width="300" Height="525" x:Name="btn3" Background="Red" /><Button Width="300" Height="525" x:Name="btn4" Background="Green" /><Button Width="300" Height="525" x:Name="btn5" Background="Yellow" /></StackPanel></Canvas></Window>
- wpf实现仿苹果水平滑动效果
- Android 仿苹果滑动效果
- 仿QQ身边的人的水平滑动效果
- Android仿苹果有滑动效果的SwitchButton
- android仿苹果SwitchButton效果的实现
- 仿QQ5.3.1左右滑动效果实现
- wpf实现iphone滑动效果demo
- android 100行代码实现 仿苹果滑动选择器WheelView
- android 十字架效果实现(水平和垂直滑动)
- 简易实现 TextView单行文本水平触摸滑动效果
- 仿苹果的滑动开关
- mobiscroll实践:移动端仿苹果select效果的实现
- Android实现仿网易首页选项卡动态滑动效果
- 仿QQ tab滑动效果
- 仿path首页滑动效果
- 仿iOS滑动返回效果
- Android高仿QQ左右滑动菜单的效果实现方式之安卓菜单左右滑动效果实现方式
- 自定义ViewGroup实现水平滑动
- 线程间通信
- picture control
- data mining decision tree
- XML简单操作-XSL
- 资源推荐 五个常用MySQL图形化管理工具
- wpf实现仿苹果水平滑动效果
- <追忆张孝祥> 郭新明:一辈子的朋友(修订版)
- Mac 10.6与Win7 文件共享
- 基数排序【经典】
- data mining statistical modeling
- Android成长之路-手势库的创建
- ORACLE的数据类型float
- [转] 如何快速通过研究生学位论文的查重问题(留着,马上就能用到了)
- VB.NET 在项目中添加App.config的配置