I have a WPF application with two windows, MainWindow and Window2. MainWindow was created by Visual Studio (and then modified by me). I then right-clicked on my project and chose Add -> Window. I modified the new window XAML and added a button to my main page with this click handler:
private void OnTest(object sender, RoutedEventArgs e)
{
var tst = new Window2();
tst.Show();
}
Clicking on the button with that handler results in an exception being thrown:
System.Windows.Markup.XamlParseException: 'The visual tree has been changed during a 'VisualTreeChanged' event.'
The line that threw the exception is
tst.Show();
Obviously, I'm missing something basic, but I have no idea what it is.