TranslateTransform Problem while changing CenterX and CenterY Properties on RotateTra
Hi All,
I wrote utility that has border and rectangle in it.
I can drag the rectangle out of the border, and i can do TranslateTransform and RotateTransform on the rectangle.
The rectangle has RenderTransformOrigin set to : 0.5,0.5.
When i drag the rectangle and do rotate and then drag again, all is working just fine, the rectangle rotate around his center Point (RenderTransformOrigin=0.5,0.5).
Now i want that the rotation center will be from the center of the border, even if i dragged the rectangle out of the border.
When i change the CenterX and CenterY properties of the RotateTransform, to be fit with the offset of the rectangle position (So that the rotation center will be the center of the border), and then try to drag again, the rectangle isn't drag to the right position.
what is wrong ?
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Controls.Primitives;
using System.Diagnostics;
using System.ComponentModel;
public partial class Window1 : System.Windows.Window , INotifyPropertyChanged
{
private int step = 5;
private double offsetX = 0;
private double offsetY = 0;
private int angle = 0;
private double flipX = 1.0;
private double flipY = 1.0;
private bool isDragging = false;
private Point startPoint = new Point();
#region Properties
public double FlipY
{
get { return flipY; }
set { flipY = value; OnPropertyChanged(this, "FlipY"); }
}
public double FlipX
{
get { return flipX; }
set { flipX = value; OnPropertyChanged(this, "FlipX"); }
}
public int Angle
{
get { return angle; }
set
{
angle = value;
if (Math.Abs(angle) == 360)
angle = 0;
OnPropertyChanged(this, "Angle");
}
}
public double OffsetX
{
get { return offsetX; }
set { offsetX = value; OnPropertyChanged(this, "OffsetX"); }
}
public double OffsetY
{
get { return offsetY; }
set { offsetY = value; OnPropertyChanged(this, "OffsetY"); }
}
#endregion
public Window1()
{
InitializeComponent();
this.KeyDown += new KeyEventHandler(Window1_KeyDown);
MyGrid.RenderTransform.Changed += new EventHandler(RenderTransform_Changed);
}
Bookmarks