Carlos
Carlos

Reputation: 945

How can I tell which TextBox had focus last?

I have an MVVM application with various TextBox controls and a virtual keypad. (This application is to run on a touch screen system, with no keyboard). To change the value of a TextBox, the user has to touch the TextBox and then use the virtual keypad to enter a number. How can my VM know which TextBox to change when it gets the command from the keypad?

Upvotes: 2

Views: 1152

Answers (2)

user1228
user1228

Reputation:

The ViewMoel is unconcerned with the View, and as such this should not be passed to the ViewMdel.

If I needed to track this, I would use the View's codebehind (I know, I know) or create a WPF behavior* that does this for me.

*using Attached DependencyProperties, is normally how I do this.

Upvotes: 0

Arsen Mkrtchyan
Arsen Mkrtchyan

Reputation: 50712

if you mean WPF use FocusManager.GetFocusedElement also look here

Upvotes: 1

Related Questions