3

I am having trouble causing an 'autohide' dock to appear programmatically.

Couldn't find any answer around the net, though the following SO Question suggested that .Show() should have done the trick

I've tried this on the latest NuGet version of the code.

My test code is below.

Anyone know how to do it? or what I'm doing wrong?

Update: apparently this is a bug in 2.7.0, I've opened an issue for it with the project. @roken's answer is an excellent workaround, so I've updated the code below to reflect it.


My test Code

Create a simple Visual Studio Windows Form application, and replace the main form's source file content with this code:

using System;
using System.Windows.Forms;
using dps = WeifenLuo.WinFormsUI.Docking;

namespace testDockPanel
{
    public partial class Form1 : Form
    {
        private dps.DockPanel dockPanel;
        private dps.DockContent dc;
        private Control innerCtrl;

        public Form1()
        {
            InitializeComponent();

            dockPanel = new dps.DockPanel();
            dockPanel.Dock = DockStyle.Fill;
            dockPanel.DocumentStyle = dps.DocumentStyle.DockingWindow;

            toolStripContainer1.ContentPanel.Controls.Add(dockPanel);

            dc = new dps.DockContent();
            dc.DockPanel = dockPanel;
            dc.DockState = dps.DockState.DockRightAutoHide;
            innerCtrl = new WebBrowser() { Dock = DockStyle.Fill };
            dc.Controls.Add( innerCtrl );

This is the part of the code that didn't work:

            // This SHOULD show the autohide-dock, but NOTHING happens.
            dc.Show();

I've replaced it with @roken's suggestion and it now works:

            dockPanel.ActiveAutoHideContent = dc;
            innerCtrl.Focus(); // This is required otherwise it will autohide quickly.

        }
    }
}
Community
  • 1
  • 1
Lockszmith
  • 2,173
  • 1
  • 29
  • 43
  • What do you mean by "show"? Are you trying to simply get the autohide content to slide out into view momentarily or permanently show the content docked to the right? – roken Dec 12 '12 at 16:42

1 Answers1

5

To show a hidden autohide content, you can set the active auto content directly:

dockPanel.ActiveAutoHideContent = dc;

It's not clear to me if the inability to activate the content via Show() is a bug that has been introduced. If you have a free moment could you try running the code you provided against version 2.5.0 to see if Show() activates the content like you expect?

roken
  • 3,946
  • 1
  • 19
  • 32
  • Thanks! I'm going to try it now and your suggestion too. – Lockszmith Dec 12 '12 at 17:40
  • Fantastic! works great. Testing with 2.5.0 the `.Show()` worked, so this is apparently a bug in 2.7.0, I'll open a new issue on the project's github. Thanks! – Lockszmith Dec 12 '12 at 18:23
  • Issue opened for this bug: https://github.com/dockpanelsuite/dockpanelsuite/issues/80 – Lockszmith Dec 12 '12 at 18:26
  • also tested with 2.6.0.1 (other version available via NuGet), and the bug is there too. – Lockszmith Dec 12 '12 at 18:35
  • @Lockszmith awesome, thanks for taking the time to narrow that down – roken Dec 12 '12 at 18:59
  • The behavior change comes from this change set, https://github.com/dockpanelsuite/dockpanelsuite/commit/34efe3590c0272ac596f0a146a5891ad1387a3ab, which attempted to address another issue. We need to revisit both of them so as to find a fix that solves both of them. – Lex Li Jan 19 '13 at 12:10