Articles in this section
Category / Section

How to stop drag drop a WPF DocumentContainer Tab to specified position?

1 min read

In DockingManager, the following code example describes you how to stop a drag drop document tab on desire position. For Example, here you can avoid dropping on 0th position. In PreviewDrop event of document container, check the Index of the target item, if the target item is 0, then handle the event.

XAML

<syncfusion:DockingManager Name="dockingmanager"  UseDocumentContainer="True">
            <ContentControl Content="Document" 
                        syncfusion:DockingManager.State="Document"
                        syncfusion:DockingManager.Header="Document1">
            </ContentControl>
            <ContentControl Content="Document"
                        syncfusion:DockingManager.State="Document"
                        syncfusion:DockingManager.Header="Document2">
            </ContentControl>
            <ContentControl Content="Document"
                        syncfusion:DockingManager.State="Document"
                        syncfusion:DockingManager.Header="Document3">
            </ContentControl>
  </syncfusion:DockingManager>

 

C#

public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();            
            (dockingmanager.DocContainer as DocumentContainer).PreviewDrop += MainWindow_PreviewDrop;
        }
        void MainWindow_PreviewDrop(object sender, DragEventArgs e)
        {
            DocumentTabControl tabcontrol = VisualUtils.FindDescendant(sender as Visual, typeof(DocumentTabControl)) as DocumentTabControl;
            if (tabcontrol != null)
            {
                TabItemExt tabitem = VisualUtils.FindAncestor(e.OriginalSource as Visual, typeof(TabItemExt)) as TabItemExt;
                if (tabitem != null)
                {
                    int location = tabcontrol.Items.IndexOf(tabitem);
             // Check the index position based on our requirement
                    if (location == 0)
                    {
             // Getting Find Decendant to collapsed the adorner after handling the drop
                        InsertionAdorner adorner = FindDescendant(tabcontrol, typeof(InsertionAdorner)) as InsertionAdorner;
                        if (adorner != null)
                        {
                            adorner.Visibility = Visibility.Collapsed;
                            (sender as DocumentContainer).ShowDragAdorner = false;
                        }
                        e.Handled = true;
                    }
                }
            }
        }
        public static Visual FindDescendant(Visual startingFrom, Type typeDescendant)
        {
            Visual visual = null;
            bool result = false;
            int iCount = VisualTreeHelper.GetChildrenCount(startingFrom);
 
            for (int i = 0; i < iCount; ++i)
            {
                Visual child = VisualTreeHelper.GetChild(startingFrom, i) as Visual;
 
                if (typeDescendant.IsInstanceOfType(child) && (child as UIElement) != null && (child as UIElement).Visibility==Visibility.Visible)
                {
                    visual = child;
                    result = true;
                }
                if (!result)
                {
                    if (child != null)
                    {
                        visual = FindDescendant(child, typeDescendant);
                        if (visual != null)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    break;
                }
            }
            return visual;
        }
    }

Conclusion

I hope you enjoyed how to stop drag drop a document tab to specified position.

You can refer to our WPF DocumentContainer feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WPF DocumentContainer example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!


Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied