如何使用wpf mvvm在按钮单击上聚焦文本框 [英] How to focus textbox on button click using wpf mvvm

查看:306
本文介绍了如何使用wpf mvvm在按钮单击上聚焦文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨晚安朋友,



我通过许多文章点击了按钮点击的文本框。



但我无法理解。因为没有教程或特定的博客。在所有的帖子中只有讨论正在进行。

我是wpf和mvvm的新手。我试图制作一个wpf应用程序,但在wpf中设计表单之后。我有一个新的按钮,我希望如果我点击新按钮第一个文本框应该集中。或者如果由于验证而发生任何错误,应该关注相关文本框。

所以任何人都可以帮助我以最容易理解的方式做到这一点。

i如果有人能帮助我,我将不胜感激。





提前致谢

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

推荐答案

这可以像 MyTextBox.Focus 一样简单。首先,它会起作用,因为你要求按下按钮,当所有内容都被渲染并显示在屏幕上时。但在许多情况下,您可能需要解决更复杂的聚焦问题,这不是一个简单的WPF主题: http://msdn.microsoft.com/en-us/library/aa969768%28v=vs.110%29.aspx [ ^ ]。



我不知道为什么你需要一个特定的博客。原始文档通常就足够了。



但首先,我建议您检查一下您的UI设计。把重点放在按钮点击上听起来很奇怪。



-SA
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


这篇关于如何使用wpf mvvm在按钮单击上聚焦文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆