Simpler.Net.Wpf.SimplerWindow - modo-lv/Simpler.Net GitHub Wiki

SimplerWindow

This is an "attachment" that gives improved functionality to the WPF's Window class.

Usage

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();

        var win = new SimplerWindow(this);
        win.FullyLoaded += OnFullyLoaded;
    }

    private void OnFullyLoaded(object sender, EventArgs eventArgs)
    {
        // Runs when all bindings are resolved
    }
}

FullyLoaded event

In WPF, the Loaded event is raised as soon as the window has finished loading, which can be (and most often is) before things such as bindings take effect. For example, if you bind a text box to a string property that is assigned a value at the constructor, Loaded will probably trigger while the text box is still blank.

FullyLoded event triggers after the form is fully loaded, including resolving all the data bindings.

In addition, it also works as a workaround for the missing exceptions bug/feature of 64-bit Windows.

CenterOwner()

There is a bug in WPF that centers windows incorrectly when Window.WindowStartupLocation is set to CenterParent and the windows are loaded/constructed/resized dynamically. This method avoids that (and is called automatically on any Window that has a SimplerWindow attached to it.