本文介绍了拖曳标签页以显示在最前面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将数据从应用程序外部拖到TabControl上.我希望能够将一个选项卡拖到最前面.TabControl和TabItems上的拖动事件似乎仅对活动选项卡触发,并且仅在拖动选项卡内容而不是选项卡"本身时触发.

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.

该控件的标记是:

<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和下面的单个TabItem中,并附加到DragOver和DragEnter事件,但是如上所述,在拖动选项卡本身时似乎没有触发行为.

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
        }
    }
}

推荐答案

您必须在TabControl上设置AllowDrop ="True"才能触发事件

You have to set AllowDrop="True" on the TabControl in order for the events to fire

这篇关于拖曳标签页以显示在最前面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 16:22