title: Close a window in Avalonia GUI
body: <p>I have created a login screen using Avalonia UI according to the MVVM pattern. What I am struggling to do is when a user clicks the login button I want to close that login page and redirect to a new window. So below you can find the code.</p>
  <p><strong>MainWindow.axaml</strong></p>
  <pre><code>&lt;Label&gt;Username&lt;/Label&gt;
  &lt;TextBox Text=&quot;{Binding Name}&quot; Watermark=&quot;Username&quot;&gt;&lt;/TextBox&gt;
  &lt;Label&gt;Password&lt;/Label&gt;
  &lt;TextBox PasswordChar=&quot;*&quot; Text=&quot;{Binding Password}&quot; Watermark=&quot;Password&quot;&gt;&lt;/TextBox&gt;
  &lt;Button Command=&quot;{Binding Login}&quot;  Width=&quot;315&quot;&gt;Login&lt;/Button&gt;
  </code></pre>
  <p><strong>MainWindowViewModel.cs</strong></p>
  <pre><code>public void Login()
              {
                  Users userDetails = Database.createDB();
      
                  if (Name == userDetails.userName &amp; Password == userDetails.password) {
                      var window1 = new Window1();
                      window1.Show();
                  }
                  else
                  {
                      Text = &quot;Invalid username and password.&quot;;
                  }
              }
  </code></pre>
  <p>So I can create a new window but I can’t close the login screen. So how can I close the Login Screen?</p>