问题
I'm dragging data from outside my application onto a TabControl. I'd like to be able to drag over a "tab" and have that tab brought to the front. The drag events on the TabControl and the TabItems only seem to fire for the active tab, and only fire when dragging over the tab content, not the "tab" itself.
The markup for the control is:
<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>
I've tried adding behaviours to both the TabControl and the individual TabItems, below, attaching to the DragOver and DragEnter events, but as mentioned above, none seem to fire whilst dragging over the tab itself.
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
}
}
}
回答1:
You have to set AllowDrop="True" on the TabControl in order for the events to fire
来源:https://stackoverflow.com/questions/13625387/dragging-over-a-tab-to-bring-to-front