Tuesday, October 6, 2009

Correct way to Load a window in WPF

Here is the correct way to load a window in WPF. Notice the hooking the Loaded event in the constructor.

public MainWindow()
{
InitializeComponent();
Loaded += new RoutedEventHandler(Window_Loaded);
//MyBigRoutine(); -- Don't do this.
}

private void Window_Loaded(object sender, RoutedEventArgs e)
{
MyBigRoutine();
}

No comments: