WPFUserControl help
hi, so I create a hangman game via wpf (c# and xaml based) and I have two game screens: menu and the actual game.
my menu is set to be my MainWindow and my game is set to be Page1.
I have a button in my MainWindow that sends me to Page 1 and works just fine, but for some reason doing the same thing from page1 to MainWindow crashes the program with a weird exeption.
(the two pics with no exeptions are from Mainwindow -> Page1, the expetions are form Pag1 -> MainWindow)
9 Replies
trying a different approach, i don't even know anymore.
I don't need a hero, i need the whole s.h.i.e.l.d Helicarrier
So a
<Window>
must be a root element. It can't contain other <Window>
s.When I do navigation, I typically do one
<Window>
which has a <ContentControl>
and then swap in/out a child control made as a <UserControl>
. WPF also has a Page
/Frame
system that I don't use. There's also Window
-> Window
navigation, but it's more complicated and I don't recommend it for most cases anyways.can you pls explain more about contentcontrol?
i've set my game to now be in usercontrol and not in page
and i've set a button on my MainWindow to transfer me over to my UserControl
I still have the same problem while going from my UserControl to my MainWIndow tho
HangMan.UserControl1 game = new HangMan.UserControl1();
this.Content = game;
again, by adding those i'm able to go from MainWindow to UserControl1 via button, but not vice versa
Can you explain exactly what you mean by that? Compiler error? Runtime exception? Something else?
nvm, i finally fixed it
created 2 usercontrols with one of em' being my menu and one of being my game
then I changed the MainWindow code so now all it does is set the main window content to be usercontrol2 which is my menu
and going between usercontrols is now done
ty
Yeah, that's how you do it. Your
Window
should be basically empty besides handling some navigation stuff so it can swap in/out content.yup, tysm, i've been at it for oh so long