Dragging over a tab to bring to front

♀尐吖头ヾ 提交于 2019-12-12 20:02:54

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!