日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > asp.net >内容正文

asp.net

WPF 跟随拖动改变的三次贝塞尔曲线思路

發(fā)布時(shí)間:2023/12/4 asp.net 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 WPF 跟随拖动改变的三次贝塞尔曲线思路 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

代碼不多,思路也很簡(jiǎn)單,

先看看效果:

簡(jiǎn)單示例,所有代碼都在MainWindow.xaml和MainWindow.xaml.cs內(nèi),


Xaml代碼:

<Window x:Class="WPFDemos.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:local="clr-namespace:WPFDemos"mc:Ignorable="d"x:Name="widnow"WindowStartupLocation="CenterScreen"UseLayoutRounding="True"Background="LightBlue"FontSize="16"Title="拖動(dòng)" Height="500" Width="1000"><Window.Resources><ControlTemplate x:Key="template" TargetType="{x:Type Thumb}"><Grid x:Name="bg"><Grid.Background><LinearGradientBrush ><GradientStop Color="Red" Offset="0."/><GradientStop Color="Blue" Offset="0.5"/><GradientStop Color="Green" Offset="1"/></LinearGradientBrush></Grid.Background></Grid><ControlTemplate.Triggers><Trigger Property="IsDragging" Value="True"><Setter TargetName="bg" Property="Background" Value="DarkGray"/></Trigger></ControlTemplate.Triggers></ControlTemplate></Window.Resources><Grid><Canvas x:Name="canvas" Margin="0,0"><Thumb x:Name="thumb1" Canvas.Top="0" Canvas.Left="0" Width="40" Height="40" Template="{StaticResource template}" DragDelta="Thumb_DragDelta"/><Thumb x:Name="thumb2" Canvas.Top="200" Canvas.Left="200" Width="40" Height="40" Template="{StaticResource template}" DragDelta="Thumb_DragDelta"/><Path x:Name="path" Data="M 0,0 c 200,0 100,300 300,300" Height="200" Stretch="Fill" Stroke="Green" StrokeStartLineCap="Round" StrokeEndLineCap="Round" StrokeThickness="5" Width="200" Canvas.Left="381" Canvas.Top="105" RenderTransformOrigin="0.5,0.5"><Path.RenderTransform><TransformGroup><ScaleTransform x:Name="scale" ScaleX="0"/></TransformGroup></Path.RenderTransform></Path></Canvas></Grid> </Window>

后臺(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)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。