[Version 2.0] 5th document becomes the first tab

Jul 26, 2013 at 11:54 PM
Edited Jul 27, 2013 at 12:03 AM
I'm adding new docs via commands in the viewmodel. For the firts 4 tabs everything works fine, the last document is actually the last tab from left to right. When I add the 5th document, it becomes the "first" tab to the left. Anyone knows why I'm experiencing this behavior?

edit: This is not happening with the default theme until all the horizontal space available is filled. I'm experiencing the issue above with Metro theme.
Aug 2, 2013 at 1:11 PM
Edited Aug 2, 2013 at 1:14 PM
I have the same problem.
The issue occurs when setting any theme via „<DockingManager.Theme>“ (even the default generic theme) and then adding more than 5 tabs.
All new documents becomes the first and all tabs can’t be dragged because they jump after some mouse movement to the left side of the dock.

Only when setting no theme at all everything works fine. So i guess it’s not a bug in the themes, but a bug in the process of changing the theme.

The issue can simply be replicated by using the MvvmTestApp and adding
<avalonDock:DockingManager.Theme>
  <avalonDock:GenericTheme/>
  <!-- <avalonDock:VS2010Theme/>  or any other -->
</avalonDock:DockingManager.Theme>
to the DockingManager.

Sorry for my bad english skills.
Aug 5, 2013 at 7:34 PM
I suspected the issue could be related to the amount of space available for the tabs, so I forced the dockingmanager width to overflow its parent window size.
Actually, this change made some additional tab showing up in the correct sequence. However I haven't find any setting that could trigger this behaviour. anyone?
Aug 6, 2013 at 11:07 PM
Edited Aug 7, 2013 at 12:06 AM
Your assumption was right that the issue could be related to the amount of space available. That was the hint i needed. Thanks.

After some long search i found the method that "kicks" the tab back on the first position.

After modifying "ArrangeOverride" in "Xceed.Wpf.AvalonDock.Controls.DocumentPaneTabPanel" to
protected override Size ArrangeOverride(Size finalSize)
{
    var visibleChildren = Children.Cast<UIElement>().Where(ch => ch.Visibility != System.Windows.Visibility.Collapsed);
    var offset = 0.0;
    var skipAllOthers = false;
    foreach (TabItem doc in visibleChildren) {
        var layoutContent = doc.Content as LayoutContent;
        if (skipAllOthers || offset + doc.DesiredSize.Width > finalSize.Width) {
            if (layoutContent.IsSelected && !doc.IsVisible) {
                var parentContainer = layoutContent.Parent as ILayoutContainer;
                var parentSelector = layoutContent.Parent as ILayoutContentSelector;
                var parentPane = layoutContent.Parent as ILayoutPane;
                int contentIndex = parentSelector.IndexOf(layoutContent);
                if (contentIndex > 0 &&
                    parentContainer.ChildrenCount > 1) {
                    parentPane.MoveChild(contentIndex, 0);
                    parentSelector.SelectedContentIndex = 0;
                    return ArrangeOverride(finalSize);
                }
            }
            doc.Visibility = System.Windows.Visibility.Hidden;
            skipAllOthers = true;
        } else {
            doc.Visibility = System.Windows.Visibility.Visible;
            doc.Arrange(new Rect(offset, 0.0, doc.DesiredSize.Width, finalSize.Height));
            offset += doc.ActualWidth + doc.Margin.Left + doc.Margin.Right;
        }
    }
    return finalSize;
            
    /* original version 
    restart:
    var visibleChildren = Children.Cast<UIElement>().Where(ch => ch.Visibility != System.Windows.Visibility.Collapsed);
    double offset = 0.0;
    bool skipAllOthers = false;
    foreach (TabItem doc in visibleChildren)
    {
        var layoutContent = doc.Content as LayoutContent;
        if (skipAllOthers || offset + doc.DesiredSize.Width > finalSize.Width)
        {
            if (layoutContent.IsSelected)
            {
                var parentContainer = layoutContent.Parent as ILayoutContainer;
                var parentSelector = layoutContent.Parent as ILayoutContentSelector;
                var parentPane = layoutContent.Parent as ILayoutPane;
                int contentIndex = parentSelector.IndexOf(layoutContent);
                if (contentIndex > 0 &&
                    parentContainer.ChildrenCount > 1)
                {
                    parentPane.MoveChild(contentIndex, 0);
                    parentSelector.SelectedContentIndex = 0;
                    goto restart;
                }
            }
            doc.Visibility = System.Windows.Visibility.Hidden;
            skipAllOthers = true;
        }
        else
        {
            doc.Visibility = System.Windows.Visibility.Visible;
            doc.Arrange(new Rect(offset, 0.0, doc.DesiredSize.Width, finalSize.Height));
            offset += doc.ActualWidth + doc.Margin.Left + doc.Margin.Right;
        }
    }

    return finalSize;*/
}
it seems like everything works fine now. What i don't understand is why it worked before when no theme was set ?