ScreenManagement better practices ?! Textbox not focusing
- by xykudyax
I saw a question here using DataTemplates with WPF for ScreenManagement, I was curious and I gave it a try I think the ideia is amazing and very clean. Though I'm new to WPF and I read a lot of times that almost everything should be made in XAML and very little should be "coded behind".
My questions resolves about using the datatemplate ideia, WHERE should the code that calls the transitions be? where should I define which commands are avaiable in which screens.
For example:
[ScreenA]
Commands:
Pressing B - Goes to state B
Pressing ESC - Exits
[ScreenB]
Commands:
Pressing A - Goes to state A
Pressing SPACE - Exits
where do I define the keyEventHandlers? and where do I call the next screen? I'm doing this as an hobby for learning and "if you are learning, better learn it right" :)
Thank you for your time.
Yes the Q/A I was talking is: What's a good way to handle game screen management in WPF?
What I've done so far was to create a Screen class (derived from UserControl) and create some virtual methods:
- one for Initializing stuff (like focus a given component by default)
- another for inputHandling I handle it by using a switch case and by listening to the PreviewKeyDown event from the parent container (MainWindow) Im not able to do it another way! Help?!.
- and a finally one that removes the keyEvent method (when the screen is terminated)
Parent.PreviewKeyDown -= OnKeyDown;
am I doing okay? I face a problem.
When I add a new screen (userControl) containing a TextBox I'm not able to give it autofocus :/ The Caret is there but is not blinking and I have to hit "TAB" before being able to input anything at all :/