1

當在用戶拖動某項瀏覽器窗口,並釋放按鈕之外appliaction之外,並返回給應用程序後拖曳指標仍清晰可見,整個操作不取消使用TreeViewDragDropTarget。有關此問題的任何解決方法?TreeViewDragDropTarget和Silverlight邊界問題

回答

1

只是發表我的回答對Silverlight的論壇有: 聯播ItemDragStarting事件下面的事件處理程序。

private void DragDropTarget_ItemDragStarting(object sender, ItemDragEventArgs e) 
     {      
      Application.Current.RootVisual.CaptureMouse(); 
      Application.Current.RootVisual.MouseLeftButtonUp += (s, ee) => 
       {     
        this.ReleaseMouseCapture(); 
        Point p = ee.GetPosition(Application.Current.RootVisual); 
        if (VisualTreeHelper.FindElementsInHostCoordinates(p, Application.Current.RootVisual).Count() == 0) 
        {    

         // If mouse is released outside of the Silverlight control, cancel the drag  
         e.Cancel = true; 
         e.Handled = true; 
        } 
       };   
     } 
0

我不確定lambda表達式是否解決了自動取消註冊鼠標句柄的情況。

我重寫了一下這個解決方案。

protected override void OnItemDragStarting(ItemDragEventArgs eventArgs) 
    { 
     Application.Current.RootVisual.CaptureMouse(); 
     MouseButtonEventHandler handlerMouseUp = null; 
     handlerMouseUp = (s, ee) => 
     { 
      this.ReleaseMouseCapture(); 
      if (handlerMouseUp != null) 
      { 
       Application.Current.RootVisual.MouseLeftButtonUp -= handlerMouseUp; 
      } 
      Point p = ee.GetPosition(Application.Current.RootVisual); 
      if (VisualTreeHelper.FindElementsInHostCoordinates(p, Application.Current.RootVisual).Count() == 0) 
      { 

       // If mouse is released outside of the Silverlight control, cancel the drag  
       eventArgs.Cancel = true; 
       eventArgs.Handled = true; 
      } 
     }; 
     Application.Current.RootVisual.MouseLeftButtonUp += handlerMouseUp; 

     if (!eventArgs.Handled) 
      base.OnItemDragStarting(eventArgs); 
    } 

在我的情況下,我還擴展了TreeViewDragDropTarget類。希望這對有人會有希望。