Search code examples
c#wpfwindow

Setting window name causes null reference wpf


When I set Window.name = "window name here", I get a null reference exception on Window.Show(). Please see code:

                MyWindow = new Window {
                                      ResizeMode = ResizeMode.NoResize,
                                      WindowStyle = WindowStyle.None,
                                      // set content and other properties here...
                                      WindowStartupLocation = WindowStartupLocation.CenterScreen,
                                      Name = "Customize Toolbar" // Omitting this allows code to run, leaving this causes null reference exception
                                  };

Why does setting the name cause this issue? setting the Title does not cause a problem.


Solution

  • Try removing the space from your Name. Use something like

    Name = "CustomizeToolbar"