1

I'm trying to create a "Guide" app for a videogame. I want a button to clear everything in the window and show something else instead of creating another window. I've been using the code:

Window1 w1 = new Window1();
        w1.Show();
        this.Close();

Instead of this method, which closes the current window and opens a new one, is there a way to clear everything in the window and pop up other information?

minglefrog
  • 29
  • 3
  • 1
    You mean like a "Wizard" kind of thing? See [this answer](https://stackoverflow.com/a/287210/982149) - is that what you mean? – Fildor May 06 '20 at 12:40
  • Here's the example: the user starts the app. They are then prompted to choose a category of information and when they choose one they get that information without opening a new window. What I want is for the Main Window to erase everything it has and replace its information with other information. – minglefrog May 06 '20 at 12:42
  • Or just replace the current Window's Content. – Clemens May 06 '20 at 12:43
  • Exactly! Is there a way to use a button in a way that replaces the main window with another one without opening a new tab? – minglefrog May 06 '20 at 12:44
  • _"What I want is for the Main Window to erase everything it has and replace its information with other information."_ - sounds like a browser with static web pages... – Fildor May 06 '20 at 12:45
  • I still don't get it... Sorry, I'm new to programming, I'm trying to figure this out, – minglefrog May 06 '20 at 12:48
  • In WPF (as well as other UI frameworks) you have basically a "tree" of components. Some are "Layout" components that control placement of other components, others are controls like buttons, textboxes, etc etc. In code, you can take one of those nodes in the tree, delete it and replace it with another. For the user, this looks like "something disappeared and something else emerged instead". So, you just need to find the right layout, build your controls and swap them out, as you wish. But:... – Fildor May 06 '20 at 12:56
  • ... In the early days of the internet. When the world was still roamed by dinosaurs and rubber boots used to be made out of wood ... ;) - HTML and "browsers" that rendered it was invented. Its purpose: Display information. But more: You'd have "links" which - when clicked - navigated the view to display another set of information ... sounds familiar? (Sorry 'bout the fun. Sitting in quarantine ... but seriously: consider markup.) WPF feels a peculiar choice to me given the requirements. – Fildor May 06 '20 at 12:59
  • 1
    Thanks, Fildor, that was really helpful! Don't worry about the fun aspect of it, I need some of it or else it's going to be a pain to learn programming! What I discovered by doing some research on YouTube is that I can achieve what I want with "Views" so I just have to learn how to let the user switch those and I'll be set :) – minglefrog May 06 '20 at 13:05

1 Answers1

1

You could create a Frame in your MainWindow and display different pages.

Xaml Frame:

<Frame x:Name="MainFrame" NavigationUIVisibility="Hidden" />

After that you create a new Page-Control and navigate to it

var page = new CustomerPage();
MainFrame.Navigate(page);
Tommehh
  • 872
  • 1
  • 17
  • 44