© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
1 reply
.rev1k

❔ How to close window in WinUI 3

I have an app that consists of 2 parts. 1st part is Login form, where user needs to enter login and password. If they are correct, it start "Editor" window where user can work.

For now in order to launch second window I use:

var editorWindow = new EditorWindow();
editorWindow.Activate();
var editorWindow = new EditorWindow();
editorWindow.Activate();


The problem is that Login window is still there, and while it is not critical, I still want to close it after Login is done.

First time I tried to add Window.Close() after opening the 2nd window in the .cs file of 1st Window, so

var editorWindow= new EditorWindow();
editorWindow.Activate();

var oldWindow = new MainWindow();
oldWindow.Close();
var editorWindow= new EditorWindow();
editorWindow.Activate();

var oldWindow = new MainWindow();
oldWindow.Close();


Which resulted
Attempted to read or write protected memory
Attempted to read or write protected memory
eror.
I tried to do it in the 2nd Window .cs file like this:


this.InitializeComponent();

var oldWindow = new MainWindow();
oldWindow.Close();
this.InitializeComponent();

var oldWindow = new MainWindow();
oldWindow.Close();

Which resulted the same error


So how can I do this properly?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

ContentDialog Window using WinUI 3
C#CC# / help
14mo ago
✅ How do I move a Window in WinUI 3 C#?
C#CC# / help
4y ago
❔ How to allow TextBlock over window in UWP/WinUI
C#CC# / help
3y ago
❔ Anchor TreeView in WinUI 3
C#CC# / help
4y ago