In a constructor for a WPF Window, what should go before InitializeComponent() and what after?

Viewed 5732

In general, I've been initializing the properties of the Window itself before InitializeComponent() and setting up controls contained within afterwards. However, I haven't been all that consistent, and I haven't really noticed a problem with the ordering. So:

  • Am I (potentially) doing something horrible? In particular, are there any issues with setting properties of child controls before InitializeComponent()?
  • What is good style in this regard?

Edit: Since the first two answers I got were a little bit contradictory, let me be more specific:

public Foo Foo {get; protected set}
public FooWindow (Foo foo)
{
    Foo = foo;
    this.Closing += FooWindow_Closing;
    Foo.Frobbed += Foo_Frobbed;

    InitializeComponent();

    this.DataContext = this;
    this.Title = Foo.Name() + " Window";

    FooListView.ItemSource = Foo.CalculateList();

    FocusManager.SetFocusedElement(this, FooListView);
}

Is this about right? Should I just be doing MVVM and not have anything in my Window constructor?

3 Answers
Related