2012-11-29 25 views
2

我将数据从应用程序外部拖到TabControl上。我希望能够拖动“标签”并将该标签带到前面。 TabControl和TabItems上的拖动事件似乎只针对活动选项卡触发,并且只在拖动选项卡内容时触发,而不是“选项卡”本身。将标签拖动到前面

Drag to tab

该控件的标记是:

<Window 
    x:Class="DragOverTabExample.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="MainWindow" 
    Height="350" 
    Width="525"> 
    <TabControl 
     HorizontalAlignment="Stretch" 
     VerticalAlignment="Stretch"> 
     <TabItem 
      Header="Tab A"> 
      <TextBlock>Tab A</TextBlock> 
     </TabItem> 
     <TabItem 
      Header="Tab B"> 
      <TextBlock>Tab B</TextBlock> 
     </TabItem> 
    </TabControl> 
</Window> 

我已经尝试添加行为,无论是TabControl的和个人的TabItems,下方,连接到的dragover和的dragenter事件,但作为如上所述,在拖拽标签本身时,没有人看起来发火。

namespace Sample 
{ 
    public class ActivateOnDragOverBehaviour : Behavior<TabControl> 
    { 
     protected override void OnAttached() 
     { 
      AssociatedObject.DragOver += ActivateTab; 
     } 

     private void ActivateTab(object sender, DragEventArgs e) 
     { 
      // Bring hovered tab to front 
     } 
    } 
} 
+0

请告诉我们你到目前为止的代码上的TabControl设置的AllowDrop =“真”。 –

+0

@Benjamin - 我已经添加了我一直使用的示例。对于TabControl行为,我已经尝试了以上,以及附加到每个TabControls子项dragover/dragenter事件。我也尝试添加到所有TabItem控件的类似行为。 –

回答