2012-10-03 31 views
0

我有一個tab選項卡的tabcontrol。我想在用戶將其從標籤控件上「撕下」時在其自己的窗口中打開特定的選項卡。我知道在創建窗口和將選項卡項移動到該窗口方面需要做什麼。激活窗口在撕裂標籤上移動

但是,我似乎無法弄清楚如何保持窗口下的鼠標,創建後,當它被撕下;所以用戶交互是無縫的。

我有這樣的TabItem的代碼:

protected override void OnPreviewMouseMove(MouseEventArgs e) 
     { 
      base.OnPreviewMouseMove(e); 
      if(e.LeftButton == MouseButtonState.Pressed && _startPoint != null) 
      { 
       Point position = e.GetPosition(null); 

       if (Math.Abs(position.Y - _startPoint.Value.Y) > SystemParameters.MinimumVerticalDragDistance) 
       { 
        Point cursor = Utils.GetCursorPosition(); 
        var w = new AttachableWindow(){WindowStartupLocation = WindowStartupLocation.Manual, Left = cursor.X, Top=cursor.Y}; 
        w.Show(); 
        _startPoint = null; 
        e.Handled = true; 
       } 
      } 
     } 

回答

0

使用DragMove方法來獲取窗口中移動:

w.Loaded += (sender, args) => 
         { 
          (sender as Window).DragMove(); 
         }; 

編輯:要小心,在加載的情況下這樣做可能會導致窗口部分渲染。我認爲激活的事件是一個更好的選擇。