我使用serveral UserControls作为子级,使用Canvas作为Container来模仿MDI窗口,但是当我拖动UserControl时,它的移动是如此缓慢! 事件如下:
GTitle.MouseLeftButtonDown += GTitleMouseButtonDownHandler;
GTitle.MouseMove += MouseMoveHandler;
GTitle.MouseLeftButtonUp += GTitleMouseButtonUp;
和:
private void GTitleMouseButtonDownHandler(object o,MouseButtonEventArgs e)
{
oldPoint = e.GetPosition(MyParent);
GTitle.CaptureMouse();
}
private void MouseMoveHandler(object o, MouseEventArgs e)
{
Point MovePoint = e.GetPosition(MyParent);
if (GTitle.IsMouseCaptured)
{
var offset = MovePoint - oldPoint;
Position = new Point(Position.X + offset.X, Position.Y + offset.Y);
oldPoint = MovePoint;
}
}
private void GTitleMouseButtonUp(object sender, MouseButtonEventArgs e)
{
if (GTitle.IsMouseCaptured)
GTitle.ReleaseMouseCapture();
}
public Point Position
{
get { return (Point)GetValue(PositionProperty); }
set { SetValue(PositionProperty, value); }
}
public static readonly DependencyProperty PositionProperty =
DependencyProperty.Register("Position", typeof(Point), typeof(ChildBaseEx2),
new UIPropertyMetadata(new Point(-1, -1) ,new PropertyChangedCallback(PositionValueChanged)));
private static void PositionValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
if ((Point)e.NewValue == (Point)e.OldValue)
return;
ChildBaseEx2 mdiChild = (ChildBaseEx2)sender;
Point newPosition = (Point)e.NewValue;
TranslateTransform translateTransform = mdiChild.RenderTransform as TranslateTransform;
translateTransform.X = newPosition.X;
translateTransform.Y = newPosition.Y;
}
所以,当我拖动鼠标时,Usercontrol可以正常移动,但是速度有点慢,需要帮助,谢谢吗?那里有很多孩子有影响力吗?