2012-07-13 67 views
0

正如您在下面看到的,我想在組件可見性發生變化時開始移動。 因爲否則我需要用戶再次點擊才能開始移動,並且這對我的應用程序來說可用性很差。如何在Thumb上提高DragDelta事件

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; 
     } 
    } 

回答

0

我相信唯一的方法是使用反射來改變拇指的內部值。更改屬性「IsDragging」(未測試)。

0

我擡起頭來source code of Thumb,我認爲更好的辦法是模擬拇指一MouseLeftButtonEvent

var evt = new MouseButtonEventArgs(mouseDevice, timestamp, MouseButton.Left) 
{ 
    RoutedEvent = UIElement.MouseLeftButtonDownEvent 
}; 
thumb.RaiseEvent(evt);