WPF 跟随拖动改变的三次贝塞尔曲线思路
生活随笔
收集整理的這篇文章主要介紹了
WPF 跟随拖动改变的三次贝塞尔曲线思路
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
代碼不多,思路也很簡(jiǎn)單,
先看看效果:
簡(jiǎn)單示例,所有代碼都在MainWindow.xaml和MainWindow.xaml.cs內(nèi),
Xaml代碼:
后臺(tái)代碼:
using System; using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives;namespace WPFDemos {public partial class MainWindow : Window{private void UpdateThumb(){var point1 = new Point((double)thumb1.GetValue(Canvas.LeftProperty)+thumb1.Width, (double)thumb1.GetValue(Canvas.TopProperty) + thumb1.Height / 2);var point2 = new Point((double)thumb2.GetValue(Canvas.LeftProperty), (double)thumb2.GetValue(Canvas.TopProperty) + thumb2.Height / 2);path.SetValue(Canvas.LeftProperty, Math.Min(point1.X,point2.X));path.SetValue(Canvas.TopProperty, Math.Min(point1.Y,point2.Y));path.Width = Math.Abs(point1.X - point2.X);path.Height = Math.Abs(point1.Y - point2.Y);if (point1.X < point2.X){scale.ScaleX = point1.Y < point2.Y ? 1 : -1;}else{scale.ScaleX = point1.Y < point2.Y ? -1 : 1;}}public MainWindow(){InitializeComponent();UpdateThumb();}private void Thumb_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e){Thumb myThumb = (Thumb)sender; double nTop = Canvas.GetTop(myThumb) + e.VerticalChange;double nLeft = Canvas.GetLeft(myThumb) + e.HorizontalChange; Canvas.SetTop(myThumb, nTop);Canvas.SetLeft(myThumb, nLeft);UpdateThumb();}} }好了,結(jié)束了,
效果圖:
總結(jié)
以上是生活随笔為你收集整理的WPF 跟随拖动改变的三次贝塞尔曲线思路的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: JMeter压测笔记
- 下一篇: asp.net ajax控件工具集 Au