基本信息
源码名称:WPF 滑动界面(图片列表)
源码大小:10.97M
文件格式:.rar
开发语言:C#
更新时间:2019-06-30
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
WPF 界面滑动,画片列表触摸,鼠标滑动
WPF 界面滑动,画片列表触摸,鼠标滑动
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 WpfApp_FlashPrac2 { /// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } /// <summary> /// /// </summary> /// <param name="dp"></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)); 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; ////移动 DoMove(Canvas.LeftProperty, to, 0.1, 0.1, 0.5); } private void Window_Loaded(object sender, RoutedEventArgs e) { ImageBrush imageBrush = new ImageBrush(); imageBrush.ImageSource = new BitmapImage(new Uri(Environment.CurrentDirectory @"\ImagesSource\CoverImgLeft.jpg", UriKind.Relative)); this.Background = imageBrush; UserC_Images use = new UserC_Images(); grdTransfer.Children.Add(use); } } }