7

How can I change my Xaml page title dynamically in a WPF application?

4 Answers 4

12

You can set page's Title by set Title property in your code.

this.Title = "My Application" + DateTime.Now;
1
  • 1
    Make sure this comes after the call to InitializeComponent.
    – lfalin
    Mar 11, 2015 at 19:22
3

Try this.

this.WindowTitle = "Your title here";
2

You can create a function like this

public void SetPageTitle(dynamic title)
{
  string DefaultTitle = "Name";
  try
  {
    this.Title = title.ToString();
  }
  catch
  {
    this.Title = DefaultTitle;
  }
}
4
  • 2
    Why would you possibly want a dynamic parameter here?
    – Jeff
    Nov 9, 2011 at 4:09
  • So that the function could be used with different inputs like what Ekk did in this this.Title = "My Application" + DateTime.Now;
    – Allan Chua
    Nov 9, 2011 at 4:11
  • simply having a parameter of type object would allow you to call ToString() on it. The above would not change in any way except to have (object title) instead of (dynamic title)
    – Jeff
    Nov 9, 2011 at 4:33
  • 1
    but it would require a cast or boxing before you could use it. ;)
    – Allan Chua
    Nov 9, 2011 at 5:11
0

Instead of using the "THIS", you can use the name of your window.

MainWindow.Title = "My Window";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.