我正在将应用程序外部的数据拖到 TabControl 上。我希望能够拖过“标签”并将该标签带到前面。TabControl 和 TabItems 上的拖动事件似乎只针对活动选项卡触发,并且仅在拖动选项卡内容时触发,而不是“选项卡”本身。
控件的标记是:
<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
}
}
}