What are some different methods to drag and move objects around without using Horizontal or Vertical Alignment set to Left and Top

I am developing a Dashboard application where I would like the user to be able to resize and move their chart widgets to where they please. I have had problems with the being able to move and resize at the same time. The reason why is that when the chart alignments are set to the following:

chart.HorizontalAlignment = HorizontalAlignment.Left;
chart.VerticalAlignment = VerticalAlignment.Top;

...the move will work perfectly, however the resize will go crazy in undetectable directions. If I switch the alignments to the following :

chart.HorizontalAlignment = HorizontalAlignment.Stretch;
chart.VerticalAlignment = VerticalAlignment.Stretch;

...the move will be off but the resize will work decently.

The move code is as follows :

public void chart_MouseMove(object sender, MouseEventArgs e)
{
    C1Chart chart = sender as C1Chart;

       if (!ModifierKey)
       {
           if (isMouseCaptured)
           {
               // Calculate the current position of the object.
               double deltaV = e.GetPosition(null).Y - mouseVerticalPosition;
               double deltaH = e.GetPosition(null).X - mouseHorizontalPosition;
               double newTop = deltaV + (double)chart.Margin.Top;
               double newLeft = deltaH + (double)chart.Margin.Left;

               // Set new position of object.            
               chart.Margin = new Thickness(newLeft, newTop, 0, 0); 

               // Update position global variables.
               mouseVerticalPosition = e.GetPosition(null).Y;
               mouseHorizontalPosition = e.GetPosition(null).X;
          }
      }
}

The mouseVerticalPosition, mouseHorizontalPosition, isMouseCaptured are assigned in a chart mouse down event and ModifierKey is boolean to tell if any of the keyboard modifiers are pressed to know whether or not to move. This code was taken off of MSDN, but I am open to alternate solutions.

The resize code can be found here(Microsoft Example) or here(Denis Vuyka Blog). Here is my question : Is there different way to do the drag & move or the resizing (Adorner Class) that I am not seeing. Or, is there a way to use this code with an alignment hack.

Answers


Have you looked into the MouseDragElementBehavior? http://blogs.msdn.com/b/dphill/archive/2009/09/25/blend-behaviors.aspx


Need Your Help

Rails 4 Javascript: Having trouble with image paths

javascript image ruby-on-rails-4 asset-pipeline relative-path

I'm trying to get the background image to change every 6 seconds and it's always a 404 error:

Replace a element instead another element by jQuery

javascript jquery

I want replace a(or each) element(number) instead another element(number) in a class while running page.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.