5

I am using the open source library AvalonDock to support drag and drop of multiple tabs (panes) outside and back to the MainWindow and I want to disable most of the possible drop targets (or lets say layouts) like placing a tab below another or placing tabs side by side. In other words I only want to allow placing tabs in a "row of tabs" like in firefox or chrome browser.

Is there any property to disable drop targets (layouts) and if yes, can you please provide me with a short code example?

Here is a simple example of an MainWindow with three dockable panes (LayoutDocuments), which look like the TabItems of the standard TabControl of WPF (sorry, I could not post a screenshot of this):

<Window x:Class="TabTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:xcad="http://schemas.xceed.com/wpf/xaml/avalondock"
        Height="300" Width="300">
    <Grid>
        <xcad:DockingManager VerticalAlignment="Stretch">
            <xcad:LayoutRoot>
                <xcad:LayoutPanel>
                    <xcad:LayoutDocumentPane>
                        <xcad:LayoutDocument Title="Doc1">
                        </xcad:LayoutDocument>
                        <xcad:LayoutDocument Title="Doc2">
                        </xcad:LayoutDocument>
                        <xcad:LayoutDocument Title="Doc3">
                        </xcad:LayoutDocument>
                    </xcad:LayoutDocumentPane>
                </xcad:LayoutPanel>
            </xcad:LayoutRoot>
        </xcad:DockingManager>
    </Grid>
</Window>

Thanks for your help!

Hubaaa
  • 121
  • 1
  • 5

2 Answers2

1

This answer is written for AvalonDock 2.0. I don't know if this works on other versions of AvalonDock.

In the source code, there is a file Controls/OverlayWindow.cs. Change the code inside the else inside the case DropAreaType.DocumentPane: default: to hide the desired targets no matter what:

void IOverlayWindow.DragEnter(IDropArea area)
{
    ...
    switch (area.Type)
    {
        ...
        case DropAreaType.DocumentPane:
        default:
            {
                ...
                else
                {
                    areaElement = _gridDocumentPaneDropTargets;

                    _documentPaneDropTargetLeft.Visibility = Visibility.Hidden;
                    _documentPaneDropTargetRight.Visibility = Visibility.Hidden;
                    _documentPaneDropTargetTop.Visibility = Visibility.Hidden;
                    _documentPaneDropTargetBottom.Visibility = Visibility.Hidden;

                    /* ... */
                }
            }
        break;
    }
    ...
}

The ellipses are to summaries code segments.

oddRaven
  • 672
  • 1
  • 7
  • 20
0

Most UI elements in WPF have a property named AllowDrop. If you set this to false, it should stop a dragged element from being dropped on that control. However, there are also methods that you can handle during the drag and drop procedure that give the developer full control over when to disable a drop operation. Perhaps you should take a good read of the Drag and Drop Overview page on MSDN to find out more.

Sheridan
  • 68,826
  • 24
  • 143
  • 183
  • 1
    Thank you Sheridan for your answer. I do not want to disable the whole drag & drop functionality of this elements. What I want is also discussed here: [link](http://stackoverflow.com/q/2594473/2769136). The AvalonDock library mentioned above exactly supports this but also other layout options when dropping single windows back into the MainWindow (like the options in Visual Studio if you rearrange the UI Components). If there is no way to disable layout options in the AvalonDock Controls I have to implement the whole thing by myself, that's right... – Hubaaa Dec 06 '13 at 15:55