Partilhar via


MDI Windows

Johan asked me about MDI support in Avalon.  We don't plan to have a native Avalon implementation of MDI in version 1, mainly because MDI is so easy to do using Windows Forms and Windows Forms interop.  I whipped together a quick demo of this, spending far too much time getting the Avalon content to look pretty before I realized there's no good way to post a picture on this blog (grumble grumble)...

First thing I did was fire up Visual Studio & start a new project I can do next Avalon-WinForms in (see earlier posts).  I created a simple WinForms Form and set IsMdiContainer = true.  Then I created a second WinForms Form to be the child window, and put one inside the other using:

            Form f = new ChildForm();
            f.MdiParent = mainForm;
            f.Visible = true;

So far, so good, but no Avalon -- so we bring in ElementHost.  I whipped up a nifty Avalon menu & toolbar (called creatively "AvalonToolbar"), then added some code to my main window's constructor to put that Avalon toolbar inside and ElementHost, and put the ElementHost inside the window:

            ElementHost host = new ElementHost();
            host.Dock = DockStyle.Top;
            host.Height = 71;

            // somewhat boneheaded way of getting Avalon content
            // into the ElementHost
            Page1 p = new Page1();
            FrameworkElement root = p.root;
            p.Child = null;
            host.AddChild(root);

            mainForm.Controls.Add(host);

Probably would have been better to have the root of my AvalonToolbar.xaml be a Panel instead of a Page, which would have saved me the p.root/p.Child = null hassle, but for some reason I was feeling stubborn...

Finally, I did the same ElementHost thing with ChildForm, sticking a different block of Avalon content inside that Form.  And voila!  An MDI application with Avalon many/toolbar and child windows.  Took me about fifteen minutes, the single greatest time sink was getting the documentation for the IsMdiContainer property (I didn't remember the MdiParent property, I guess it has been five years since I was on WinForms...).

Comments

  • Anonymous
    July 07, 2005
    Couldn't you post the project for download?

    Thanks,
    Paulo
  • Anonymous
    July 07, 2005
    Thanks Nick,

    How far are we away from having a book or labs or even an Ascend program for Avalon?

    - Johan
  • Anonymous
    July 08, 2005
    The comment has been removed
  • Anonymous
    December 24, 2005
    I'm glad MDI's gone, actually. I hope you guys don't put it back in unless you figure out how to support non-rectangular display areas (i.e. multiple monitors) without wasting screen space or making users wrestle with aligning child windows.

    MDI was nice, but as more people are using multiple monitors, it's becoming more and more obsolete.
  • Anonymous
    January 20, 2009
    PingBack from http://www.hilpers.com/955440-umstieg-vc6-vs2005