Here is an attempt to run the answers suggested for How do I programmatically change the Title in a wpf window?
<Window x:Class="WindowTitle.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WindowTitle"
mc:Ignorable="d"
MinWidth="600" SizeToContent="WidthAndHeight" Title="{Binding MyTitle}">
<Grid Margin="5">
<Button Click="Button_Click" Content="Change Title" Width="100"/>
</Grid>
</Window>
Code-behind:
using System.Windows;
namespace WindowTitle
{
public partial class MainWindow : Window
{
private int counter = 0;
public void Button_Click(object sender, RoutedEventArgs e)
{
MyTitle = counter.ToString();
++counter;
System.Diagnostics.Debug.Assert(MyTitle != DefaultTitle);
}
public const string DefaultTitle = "Default Title";
public MainWindow() { InitializeComponent(); DataContext = this; }
public string MyTitle { get; set; } = DefaultTitle;
}
}
The code sets the title on load but not on subsequent click of the button.
Any ideas? I'm stumped.