0

The program needs to achieve multi-page switching, I used ContentControl and Page. However, in the test, it was found that when switching from Page1 to Page2 and then back to Page1, the data inside will not be saved.

Code:

In MainWindow.xaml:

<ContentControl x:Name="ShowPage" Height="450" Width="770"/>

In MainWindow.xaml.cs:

private void OpenHomePage(object sender, RoutedEventArgs e) //A button event
{
    Pages.Home Home = new Pages.Home();
    ShowPage.Content = new Frame() { Content = Home };
}

E.g: I enter "123" in the text box in Page1, I switch to Page2 and then go back to Page1, the content of the text box will disappear, and the "123" I entered is not saved.


Is there any way to save the entered data?

  • how do you switch pages – styx Jul 10 '22 at 06:13
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jul 10 '22 at 12:41
  • You must store the input in a property and then ensure to reuse the pages or data models. Don't create a new instance on each navigation. [C# WPF Navigation Between Pages (Views)](https://stackoverflow.com/a/61323201/3141792), [How do I toggle between pages in a WPF application?](https://stackoverflow.com/a/58849975/3141792) – BionicCode Jul 10 '22 at 15:05

0 Answers0