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 (6)

  1. Paulo says:

    Couldn’t you post the project for download?

    Thanks,

    Paulo

  2. Johan Myburgh says:

    Thanks Nick,

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

    – Johan

  3. James Hancock says:

    Ok, well this is possibly the dumbest decision that I have ever heard of. Probably 90+% of all applications (including Word, Excel and most other MS applications are MDI. Almost all database applications of any complexity are MDI applications.

    MS word’s use of the start bar for all windows being a perfect example of a stupid interface that people don’t like shows you exactly what you can expect when you don’t have MDI. And if you expect to fill in functionality you should have by interoping with old stuff? WOW. I can’t believe you think that’s an acceptable solution. It’s like leaving out a text box control in .net V1.0 because interoping the Win32 version is "so easy!"

    DUH.

  4. rei says:

    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.