This project is read-only.

Open a Window ?

Mar 20, 2011 at 6:12 PM

Hi there ..

i am wondering how to open a window inside the Nuclex User Interface ?
I did find the methode close() which seems to be inherited from WindoControl, 
but how do i open a window ?

Thanks in advance,


Mar 20, 2011 at 6:27 PM

Just create the Window and attach it to the parent container - eg. for a global Window add it to the Screen.Desktop.Children collection.

This can be seen in the Nuclex.UserInterface.Demo application, it opens the demonstration dialog like this:

  // Create an instance of the demonstration dialog and add it to the desktop
  // control, which means it will become visible and interactive.
  mainScreen.Desktop.Children.Add(new DemoDialog());

The entire GUI is based on the composition pattern: everything is a Control and any Control can have children. The topmost control is the "desktop" (Screen.Desktop) and any open dialogs and controls are in the .Children collection of the desktop. The controls on a dialog are in the dialog's .Children collection (the dialog itself being a Control).

Mar 20, 2011 at 6:34 PM

so you mean to hide/close a windowDialog i have to remove it from the Children´s collection in the form




Mar 20, 2011 at 6:38 PM

... and to re-open it, i have to add it to the children´s collection again ?

that was what I wanted to say in my former posting :)

Mar 20, 2011 at 7:38 PM

ok maybe i did not made myself clear enough :)


i want to be able to show and hide windows like it is common in a multi-window environment.

I understand the component-based architecture of the framework and i did set up my controls
in the way it is described in the documentation.

And after adding a WindowDialog to the mainScreen.Desktop.Children - Collection the window
appears and everything works perfect.

But then on some point i want to hide the window and re-open it later.
How do i achieve that ?


Mar 21, 2011 at 7:32 PM

Windows don't have an Open/Closed state - whether they're open or hidden is decided solely by whether they're part of the control hierarchy. The Close() method doesn't actually do anything to the window itself, it simply detaches it from its parent:

/// <summary>Closes the window</summary>
public void Close() {
  if(IsOpen) {
/// <summary>Whether the window is currently open</summary>
public bool IsOpen {
  get { return Screen != null; }

(the IsOpen property checks the screen because detached windows don't have a Screen, so it will return true whenever the window is part of a control hierarchy that's parented to a screen)

Mar 21, 2011 at 7:47 PM

ok, first of all thank you very much for your detailed and very well explaining answers, Cygon !


so if i got that right, the only two "states" a window dialog can have, is either part of the whole GUI or not.

So i assume the purpose of the WindowDialog control is not to be a Window as it is used in Window-based
WYSIWYG environments but instead to be a viewing plane which is permanently visible ?

If that is true, the architecture now makes more sense to me :)


But anyway, is there a way to realize a common window-control, for creating something like, let´s say a Confirmation Dialog,
or a SaveAs-promt dialog in which the user can type a filename, clicks the save-button and the dialog disappears ?

I have integrated the Nuclex GUI Framework into a very important project i am currently working on and i am at a point
where i can´t  substitute this GUI with another one, so i would be very thankful if you have any ideas for me ...


Mar 21, 2011 at 9:29 PM

Yep, that's exactly right.

The GUI is designed specifically for games - in other words, there's no window resizing, no data grids or menu bars. It's well suited for the typical game's user interface: main menu, save/load dialog, graphics settings etc. but not ideal if you wanted to create, say, a complex level editor with toolbars, preview windows and whatnot.

Creating a SaveAs prompt as you describe should be rather simple - create a Window, add an InputBox as child to the window, two buttons (one Ok, one Cancel). A useful pattern here is to derive your own class (let's call it "SaveAsWindow") from the Window class and set up the required controls in the Window's constructor. The demo application demonstrates this technique in its "DemoDialog" class (I styled it very much like a WinForms dialog with a .Designer.cs holding the control creation and positioning code).

One limitation you might run into is that there are no modal dialogs yet - I have the design down for a system that will allow for pop-up controls that block everything below (useful for modal dialogs, combo boxes and more) but I can't make any promises as to when I will be able to integrate it into Nuclex.UserInterface.

Mar 21, 2011 at 10:11 PM

so right back from the msdn.create forum :)

again, thank you very much for your help!

in my game i´ve already built a number of dialogs and windows - some messagebox-like dialogs, a saveAs-dialog (like the one describe above), and a few windows holding listControls which hold dozens of items. Everything works quite fine and i am very pleased with the handling of the framework.

The only issue is, as discussed, the vanishing of these dialogs. Currently i have all windows shown on the screen at the same time ... through the WindowDialog.Close() method i can close them but i am not able to bring them back - that´s my problem, but meanwhile you know that :)

So regarding to your tips, i am gonna solve this issue through simply removing these dialogs from their parents everytime i want them to disappear.

After thinking about that for a while i came up with the thought that the Children.Remove() - method and my initially desired Hide() - method are semanticaly equivalent :)

 Cygon, you did really help me !
Thank you again and i wish you all the best :)

best regards,
gimick / gadget