i want something like this but i want to create the control dynamically and probably not a user control. So far i got to this:
private void Shape_MouseMove(object sender, MouseEventArgs e)
{
Shape? obj = sender as Shape;
if (obj != null)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
if (obj.IsMouseCaptured)
{
if (!(obj is Path))
{
if (Keyboard.Modifiers == ModifierKeys.Shift)
{
Point ptCenter = new Point(obj.ActualWidth / obj.ActualHeight / 2);
Point pt = Mouse.GetPosition(obj);
double radians = Math.Atan2(pt.Y - ptCenter.Y, pt.X - ptCenter.X);
double angle = 180 * radians / Math.PI;
// Apply a 180 degree shift when X is negative so that we can rotate
// all of the way around
if (pt.X - ptCenter.X < 0)
{
angle += 180;
}
RotateTransform? rt = obj.RenderTransform as RotateTransform;
//obj.RenderTransformOrigin = new Point(0.5, 0.5);
if (rt != null)
{
rt.CenterX = ptCenter.X;
rt.CenterY = ptCenter.Y;
rt.Angle = angle;
}
else
{
obj.RenderTransform = new RotateTransform()
{
CenterX = ptCenter.X,
CenterY = ptCenter.Y,
Angle = angle
};
}
Title = angle.ToString();
}
Unfortunatelly it doesnt work as i want, the shapes behave erractically as i drag the mouse. .......................................................................................... ..........................................................................................