This project is read-only.
Window Example


In WPF and comparative to WinForms, showing a Window is very lightweight and quick.

If you are only wanting to display a topmost dialog (and it's okay for it to be "modeless" allowing you to interact with the window underneath) then, you may likely just leverage: Dialogs

However, if you want to display a true modal dialog or real window that may appear separately in the Taskbar, then read on . . .

In WPF-CPS, it is best to inherit from CPSBaseWindow when displaying a Window. See here for details on this base class: CPSBaseWindow. Also, see further below for yet another example of implementing a Window that inherits from CPSBaseWindow.

Once you have a Window class, it is relatively easy to display it. Simply "new' it up and call Show:
TestWindow tsW = new TestWindow();

This will typically launch the Window quietly and discretely into the Taskbar in a minimized state. Note that the Window will remain alive by default even if you close the parent Window from which it was launched. (This is likely different behavior than the default behavior in WinForms.)

If you want the Window to launch less discretely and on top of its parent window (with a higher z-index), then, assign Topmost equal to true:
TestWindow tsW = new TestWindow();
tsW.Topmost = true;

By default, the Window appears to launch maximized (or to last opened size.) Yet, if you want to explicitly control and set its display Height and Width, then besides setting these respective properties (and optionally, MinHeight, MaxHeight, MaxWidth, and MinWidth), also set WindowState to Normal:
TestWindow tsW = new TestWindow();
tsW.Topmost = true;
tsW.WindowState = WindowState.Normal;
tsW.Height = 50D;
tsW.Width = 50D;

Optionally, you may also want to choose ShowDialog instead of Show if you want the window to be modal, not allowing you to interact with the parent window until the new window is closed.
TestWindow tsW = new TestWindow();

Finally, here is an example of implementing a Window class which inherits from CPSBaseWindow:
public partial class TestWindow : CPSBaseWindow
        public TestWindow()
            //InitializeComponent(); NOT NEEDED SINCE NO XAML. Call base.StartInitializeComponent(); at the beginning of the Constructor and base.EndInitializeComponent() at the end instead
            base.StartInitializeComponent(Brushes.Silver, new Thickness(2));

            //base.Canvas is available

            Title = "Test Window";

            StackPanel sp1 = new StackPanel();
            sp1.Initialize(300D, 300D, ContainerType.Canvas, Orientation.Vertical);
            sp1.Background = Brushes.Khaki;

            base.AddMainParentToWindow(adornerDecorator =>
                    .SetItemBorderColorAndThickness(Brushes.Black, new Thickness(4))

                    .AddExisting<StackPanel, AdornerDecorator>(0, 0, sp1)
                    .EndComposite<AdornerDecorator, AdornerDecoratorArgs>(null);
}//end of class

Last edited Apr 3, 2014 at 5:44 AM by stagathome0069, version 15


No comments yet.