Resolved WPF How do I share data from one window with another window?

Wkesther

Member
Joined
Aug 6, 2022
Messages
24
Programming Experience
Beginner
I created a MainMenu window with three buttons called "Start", "Settings" and "Exit".
When you click on Settings, the MainWindow closes and a new Settings window opens up.
In the Settings window there are radiobuttons to choose the difficulty and a "save & exit" button.
Now I need to transfer the selected difficulty to the MainMenu in order to start the game in the selected difficulty.
Do you have an idea how I could realise that?

MainMenu.PNG
Settings.PNG
 
No, but it's generally considered the best pattern for creating WPF and other XAML-based applications. If you're just starting out with WPF, you ought to learn about MVVM now, so you can build your applications the right way and not go too far down the wrong path and have to relearn things.
 
Okay, than I should probably start learning it. Am I able to solve my "Hangman" problem with MVVM? So should I learn MVVM before creating the Hangman game?
 
I would suggest so, yes. You can do it without using MVVM but, if you're serious about creating WPF apps, you'll just have to unlearn and relearn how to do things later on if you don't learn MVVM now. It's your choice. We can help you with your current problem now without MVVM if you want but I think that you'd just be wasting time and you'll benefit by making the change now.
 
Basically, with Model-View-ViewModel, your two Windows will be two different Views. For them to share data, you would have them use the same Model. Depending on how you write your View model, you could share that one too.
 
Back
Top Bottom