На моем MainPage.xaml у меня есть несколько пользовательских элементов управления, которые я хочу иметь возможность перемещаться по всей поверхности сетки. Вот почему я добавляю их всех в TransformGroup:
this.transformGroup = new TransformGroup();
this.translation = new TranslateTransform();
this.scale = new ScaleTransform();
this.transformGroup.Children.Add(this.scale);
this.transformGroup.Children.Add(this.translation);
myCustomControl1.RenderTransform = this.transformGroup;
myCustomControl2.RenderTransform = this.transformGroup;
Теперь я могу переместить все свои пользовательские элементы управления, что дает мне «эффект прокрутки» в Grid (что-то вроде прокрутки эффекта Bing Maps).
Моя проблема:
Я хочу иметь возможность отделить свой пользовательский элемент управления от TransformGroup и переместить его независимо от остальных. В myCustomControl.xaml.cs у меня есть:
private void separateControlFromTransformGroup()
{
Grid parentGrid = (Grid)Parent;
this.transformGroup = (TransformGroup)this.RenderTransform;//backup copy of old transform group
newTransformGroup1 = new TransformGroup(); //new temporary transform group
TranslateTransform translation1 = new TranslateTransform();
CopyTranslateTransform((TranslateTransform)transformGroup.Children[1], translation1);//copy the values of transformGroup from the MainPage.xaml to temporary one (not reference)
ScaleTransform scale1 = new ScaleTransform();
CopyScale((ScaleTransform)transformGroup.Children[0], scale1);
newTransformGroup1.Children.Add(scale1);
newTransformGroup1.Children.Add(translation1);
foreach (myCustomControl brother in parentGrid.Children)
{
if (brother == this)
{
continue; (separate this control from the TransformGroup)
}
else
{
brother.RenderTransform = newTransformGroup1; //the rest of myCustromControls on the Grid in MainPage.xaml now have diffrent transform group. Now I can move selected control independent from the rest
}
}
}
После перемещения отдельного myCustomControl (с новыми значениями) я не могу связать его с остальными в transformGroup и иметь возможность перемещать все вместе. Что я должен делать? Есть ли другой способ сделать элементы управления «MoveAble» в Grid, если ни один не выбран, или выбрать только один, если какой-либо выбран?
Пожалуйста, помогите.