Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Good Evening friends,

I gone through many articals for getting focus on text box on button click.

but i am unable to understand. because there is no tutorial or a particular blog. in all the post only discussion is going on.
and i am new to wpf and mvvm. i was trying to make a wpf application but after designing form in wpf. i have one new button and in that i want if i click on new button first text box should be focused. or then if any error occurs due to validation the perticualr textbox should be focused.
so can anybody help me to do that in a easiest way that i can understand easily.
i would be grateful if anybody could help me.


Thanks in advance
Posted

1 solution

This can be as simple as MyTextBox.Focus. It will work, first of all, because you are asking to do it on button press, when everything is rendered and shown on screen. But in many cases you may need to solve more sophisticated problems of focusing, which is not a trivial WPF topic: http://msdn.microsoft.com/en-us/library/aa969768%28v=vs.110%29.aspx[^].

I don't know why would you need a "particular blog" on this. Original documentation is usually enough.

But first of all, I would advise to review your UI design. Focusing something on button click sounds weird.

—SA
 
Share this answer
 
Comments
bunty swapnil 17-Jun-14 6:12am    
Hi,
MYTextbox.focus is ok but i wanted to do using MVVM pattern not using code behind.

suppose if i clicked on button and because of some validation in textbox we are unable to retrive.
so for knowing the reason the perticular textbox should be focused and tell because of this error we are unable to redirct.

Thanks for your response

i would like to hear from your side.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900