1

As you can see below, I want to start moving when the component visibility changes. because otherwise I need the user to click again to start the movement, and that is bad in terms of usability for my application.

 public MoveILayoutControl()
    {
        InitializeComponent();
        this.IsVisibleChanged += new DependencyPropertyChangedEventHandler(MoveILayoutControl_IsVisibleChanged);
        this.moveThumb.DragDelta += new DragDeltaEventHandler(MoveThumb_DragDelta);
    }

    void MoveILayoutControl_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
    {
        if (this.IsVisible)
        {
            // Raise Drag Event !?
        }
    }

    private void MoveThumb_DragDelta(object sender, DragDeltaEventArgs e)
    {
        var myData = DataContext as ILayoutVisual;

        if (myData != null)
        {
            Point dragDelta = new Point(e.HorizontalChange, e.VerticalChange);

            if (myData.Rotation != 0)
            {
                Matrix toCalculate = ((this.Parent as FrameworkElement).RenderTransform).Value;
                if (toCalculate != null)
                {
                    dragDelta = toCalculate.Transform(dragDelta);
                }
            }
            myData.X += dragDelta.X;
            myData.Y += dragDelta.Y;
        }
    }
4

2 回答 2

0

我相信唯一的办法就是使用反射来改变拇指的内部值。更改属性“IsDragging”(未测试)。

于 2012-10-07T23:46:29.373 回答
0

我查看了源代码,Thumb我认为更好的方法是MouseLeftButtonEvent在拇指上模拟一个:

var evt = new MouseButtonEventArgs(mouseDevice, timestamp, MouseButton.Left)
{
    RoutedEvent = UIElement.MouseLeftButtonDownEvent
};
thumb.RaiseEvent(evt);
于 2016-09-16T06:27:28.817 回答