0

Currently I am creating a basic log-in UI. I have a Login window/screen and main window.

The main window has few buttons and one of them is to switch to the login window. Same with the log-in window, it has a button in order to go back to the main.

I am trying to switch between the windows but for some reason it only switches once meaning if the user starts at main, can go to log-in but can't change back and the other way around.

I have tried to add another window and check if it has something to do with going back to where I came from but its not related.

here is the c# code (if wpf needed let me know) -

Main Window :

        private void LoginNav_Click(object sender, RoutedEventArgs e)
        {
            //Switching the current window content to the login window
            
            this.Content = new LoginScreen().Content;

        }

Log-in window:

        private void BackButton_Click(object sender, RoutedEventArgs e)
        {
            // Switching current to Main window
            
            this.Content = new MainWindow().Content;

        }

When debugging it goes into the function "performs" it but nothing changes.

Anybody got an idea how to fix it? (or a more efficient way to do that)

Thanks in advance

Nadav
  • 1
  • 1
  • `new MainWindow()` is a *new* MainWindow instance, not the existing one. Besides that, you do not want to set the Content of a Window to the Content of a newly created other Window. That makes no sense. You do instead want to Show and Close Windows. – Clemens Jan 22 '22 at 13:32
  • I Did not upload to full code, I had show and close but it opened a new window and I don't want that. I want it all to happen on the same window. (seems more comfortable for the user since it actually opens a new window, changes the position, size etc) – Nadav Jan 22 '22 at 13:42
  • 1
    Then use only one Window, and do nor create new ones. Keep the MainWindow Content and just put the LoginScreen in some kind of overlay on top of the existing elements. – Clemens Jan 22 '22 at 13:45
  • check out material design, and dialog. You can create login window as user control, md even has basic anonymus textbox for password fiels. What you did is initalize new main window on top of existing one, thats what `new` means, crating new object. –  Jan 22 '22 at 16:09
  • This [example](https://stackoverflow.com/a/61323201/3141792) shows how to create a single page application like showing different screens e.g., login screen etc. – BionicCode Jan 22 '22 at 17:50

0 Answers0