Antelito
Antelito

Reputation: 85

How can i change a Page in my wpf Main Window?

i want to switch pages that are hosted on my main window. The first page (at App Start) is beeing shown correctly. But if i want to change the page it won´t happen. I even don´t get an error. It just shows the first page! Here´s my code:

The constructor of MainWindow:

public MainWindow(SchraubUser _schraubUser, string page = "")
    {
        schraubUser = _schraubUser;
        db = new AccessDatabase(schraubUser._DATABASE_PATH);

        ViewModel.ViewModel wzViewModel = new ViewModel.ViewModel(schraubUser, db);

        InitializeComponent();

        if (page == "")
        {
            Main.Content = new View.Werkzeug_Window(wzViewModel);
        }
        else
        {
            Main.Content = new View.Freigaben(wzViewModel); 
        }
    }

At Application start the optional variable is "" so the mainwindow will display View.Werkzeug_Window (works correctly).

Here`s the code for changing the page:

    private void Button_Freigaben_Click(object sender, RoutedEventArgs e)
    {
        mainWindow = new MainWindow(sb_vm.schraubUser, "Freigabe");
    }

But it will still show the first page. Why is that?

XAML of MainWindow:

<Window x:Class="SchrauberDB.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:SchrauberDB"
    mc:Ignorable="d" 
    Title="MainWindow" Height="750" Width="1100"
    WindowState="Maximized">
<Grid x:Name="mainGrid">
    <Frame x:Name="Main" />
</Grid>
</Window>

Upvotes: 1

Views: 1227

Answers (1)

Antelito
Antelito

Reputation: 85

This is so embarrassing...

    private void Button_Freigaben_Click(object sender, RoutedEventArgs e)
    {
        mainWindow = new MainWindow(sb_vm.schraubUser, "Freigabe");
        mainWindow.Show();
    }

Upvotes: 1

Related Questions