CPSBaseWindow is new as of Version 5.0.

This provides a base class that your main Window may inherit from. Make sure to add code to App.xaml that may construct your Window. For instance, in this example, I "new up" my MainWindow which inherits from CPSBaseWindow and show it:

  public partial class App : Application
        protected override void OnStartup(StartupEventArgs e)

            MainWindow mn = new MainWindow();

Also, make sure to remove StartupUri="MainWindow.xaml" from the App.xaml.
<Application x:Class="WPFContribDemo.App"

Advantages this base class provides:

1. Can get rid of the default Window.xaml. Just delete the old Window.xaml and Window.xaml.cs and then add your own Window that inherits from CPSBaseWindow.
Make sure your Window has a public constructor. At the beginning of this constructor, call base.StartInitializeComponent(). At the end of the constructor call base.EndInitializeComponent. There is no need for the normal InitializeComponent method since there is no XAML but include these new Start and End method calls instead.

2. Provides a built-in base.Canvas. This may be combined with the DialogHelpers static class in the FasterWPF.Dialogs namespace to display various Dialogs. This may be especially useful for Single-Page-Applications (SPA).

3. Provides an explicit, built-in base.AdornerDecorator and base.AdornerDecoratorGuid. This may be combined with the methods in the static class AdornerDecoratorExt. These methods allow adorning controls with validation rectangles when validating field values.

4. Provides built-in hooks to the Win32 GetWindowRect in order to provide convenience properties: base.WindowHeight and base.WindowWidth.

5. Provides built-in OPTIONAL method for manually re-sizing controls upon the Window Resize Event by overriding ResizeCorrectly; for example:

//this is an OPTIONAL method for manually re-sizing controls upon Window Resize Event
protected override void ResizeCorrectly()
    Double windowHeight = base.WindowHeight;
    Double windowWidth = base.WindowWidth - 10;

    if (windowWidth > 0)
         //get a handle to some Framework Element and set its Width and Height
         //to automatically be re-sized whenever the Window is re-sized.
Typically, the rich WPF layout controls offer enough re-sizing options, but in case you ever feel painted into a corner, you may find the above approach a straightforward way to implement custom re-sizing?

6. Provides a built-in method base.AddMainParentToWindow for adding a primary Parent to the Window via adding it to the built-in AdornerDecorator. For example:

base.AddMainParentToWindow(adornerDecorator =>
                    .AddExisting<Grid, AdornerDecorator>(0, 0, mainGrid)
                    .EndComposite<AdornerDecorator, AdornerDecoratorArgs>(null);
So, you will end up with an object graph like this: Window -> Canvas -> AdornerDecorator -> Main Parent.

Last edited Mar 20, 2014 at 1:04 AM by stagathome0069, version 30


No comments yet.