【发布时间】:2012-11-17 12:04:42
【问题描述】:
我正在将应用程序外部的数据拖到 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
}
}
}
【问题讨论】:
-
请向我们展示您目前拥有的代码。
-
@Benjamin - 我已经添加了我一直在使用的示例。对于 TabControl 行为,我已经尝试了上述方法,以及附加到每个 TabControls 子项 dragover/dragenter 事件。我还尝试了将类似行为添加到所有 TabItem 控件。
标签: .net wpf tabcontrol tabitem