Window Title in WPF

Oct 27, 2010 at 10:35 PM

What is the best way to set the Window Title based on which ViewModel is in the "MainContent" region?

Coordinator
Nov 3, 2010 at 3:29 PM

It can be difficult to bind top-level Window properties to a datacontext, especially if the datacontext is a resource inside that container.

To my knowledge the options are:

  1. Set the datacontext at the Window level (don't use a resource), which will require some code-behind in app.xaml.cs
  2. Create a control that knows how to set the container's Title property (so the Window), but can bind to a resource
  3. Use some code-behind the main window to pick up the value from the viewmodel and set the Title property

Number 3 is almost certainly simplest. Number 2 is probably the most elegant. Number 1 is pretty common.