私は図面プロジェクトに取り組んでいます。ここでは、ユーザーができるドラッグ可能なウィンドウを作成していますオブジェクトをクリックし、私たちのレイヤーでPhotoShopのように別の位置に移動します。WFP TranslateTransformエラー
プログラム私は、画面上のオブジェクトOneに対して完全に動作しています。ドラッグするだけで、任意の位置に移動できます。しかし、オブジェクトの数が増加すると、それは非常に奇妙な問題を引き起こしています。いずれかのオブジェクトをクリックすると、ウィンドウ上のすべてのオブジェクトのクラスターが作成され、クラスター全体に変換が適用されます。
注:すべてのオブジェクトは、画像であり、コンテナがキャンバスです。
使用している画像とコードは次のとおりです。
private Point _currentPoint;
private Point _ancherPoint;
private bool _isInDrag = false;
private TranslateTransform _transform = new TranslateTransform();
private Image _element;
private void DropList_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
_element = FindAnchestor<Image>((DependencyObject)e.OriginalSource);
if(_element != null)
{
_ancherPoint = e.GetPosition(DropList);
_isInDrag = true;
_element.CaptureMouse();
e.Handled = true;
}
}
private void DropList_MouseMove(object sender, MouseEventArgs e)
{
if(_isInDrag)
{
_currentPoint = e.GetPosition(DropList);
_transform.X += (_currentPoint.X - _ancherPoint.X);
_transform.Y += (_currentPoint.Y - _ancherPoint.Y);
Lbl.Content = _element.Source.ToString();
Source on which transfrom is going to happen
_element.RenderTransform = _transform;
_ancherPoint = _currentPoint;
}
}
private void DropList_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
if(_isInDrag)
{
_element.ReleaseMouseCapture();
_isInDrag = false;
e.Handled = true;
}
}
private static T FindAnchestor<T>(DependencyObject current) where T : DependencyObject
{
do
{
if(current is T)
{
return (T)current;
}
current = VisualTreeHelper.GetParent(current);
}
while(current != null);
return null;
}
これは単一のオブジェクトです。これは、私がどんな混乱もなく簡単に望む場所に移動できます。
ここには3つのオブジェクトがあります。私がそれらのいずれかをクリックすると、彼らはクラスタを作り、一緒に動くようになる。
はあなたの助けのためにありがとうございました。私はすべてのオブジェクトを同じ変換オブジェクトを使用していることを完全に忘れています。 –