Vous pouvez également essayer Visifire. Vous pouvez utiliser les graphiques et les jauges de Visifire et implémenter le comportement de glisser-déposer. Le code suivant vous aidera à construire glisser-déposer comportement dans votre application. Vous pouvez associer ce comportement à Visifire Diagramme ou jauges dans l'application Silverlight ou WPF.
Vous pouvez télécharger le code source (DragElementsInCanvasBehaviour.zip) depuis mon SkyDrive ci-dessous.
https://skydrive.live.com/?cid=61995e3895be1728&sc=documents&uc=1&id=61995E3895BE1728!106#
[ "Bonjour tout le monde" glisser-déposer classe de comportement.]
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Interactivity;
namespace DragInCanvasBehaviour
{
public class DragInCanvasBehaviour : Behavior<UIElement>
{
protected override void OnAttached()
{
base.OnAttached();
this.AssociatedObject.MouseLeftButtonDown += AssociatedObject_MouseLeftButtonDown;
this.AssociatedObject.MouseMove += AssociatedObject_MouseMove;
this.AssociatedObject.MouseLeftButtonUp += AssociatedObject_MouseLeftButtonUp;
}
protected override void OnDetaching()
{
base.OnDetaching();
this.AssociatedObject.MouseLeftButtonDown -= AssociatedObject_MouseLeftButtonDown;
this.AssociatedObject.MouseMove -= AssociatedObject_MouseMove;
this.AssociatedObject.MouseLeftButtonUp -= AssociatedObject_MouseLeftButtonUp;
}
private Canvas canvas;
private bool IsDragging = false;
private Point mouseOffset;
private void AssociatedObject_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (canvas == null)
canvas = (Canvas)VisualTreeHelper.GetParent(this.AssociatedObject);
IsDragging = true;
mouseOffset = e.GetPosition(AssociatedObject);
AssociatedObject.CaptureMouse();
}
private void AssociatedObject_MouseMove(object sender, MouseEventArgs e)
{
if (IsDragging)
{
FrameworkElement element = AssociatedObject as FrameworkElement;
FrameworkElement parent = element.Parent as FrameworkElement;
Point point = e.GetPosition(parent);
AssociatedObject.SetValue(Canvas.TopProperty, point.Y - element.Height /2);
AssociatedObject.SetValue(Canvas.LeftProperty, point.X - element.Width/2);
}
}
private void AssociatedObject_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
if (IsDragging)
{
AssociatedObject.ReleaseMouseCapture();
IsDragging = false;
}
}
}
}
Hope this helps!