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.
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
. 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
. This may be combined with the methods in the static class AdornerDecoratorExt. These methods allow adorning controls with validation rectangles when validating
4. Provides built-in hooks to the Win32 GetWindowRect in order to provide convenience properties:
5. Provides built-in OPTIONAL method for manually re-sizing controls upon the Window Resize Event by overriding
; 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:
.AddExisting<Grid, AdornerDecorator>(0, 0, mainGrid)
So, you will end up with an object graph like this: Window -> Canvas -> AdornerDecorator -> Main Parent.