添加到wpf窗口时如何将焦点设置到usercontrol的控件 [英] how to set focus to the usercontrol's control when added to a wpf window

查看:658
本文介绍了添加到wpf窗口时如何将焦点设置到usercontrol的控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户控件添加到wpf窗口时,如何将焦点设置到usercontrol的文本框。



我尝试了下面的示例。



< stackpanel orientation =Verticalfocusmanager.focusedelement ={Binding ElementName = txt1}>

解决方案

WPF聚焦是一个非常高级的主题。请从这里开始: http://msdn.microsoft.com/en- us / library / aa969768%28v = vs.110%29.aspx [ ^ ]。



在大多数情况下,你需要设置逻辑焦点。具体方法如下: http:// msdn .microsoft.com / zh-cn / library / system.windows.input.focusmanager.setfocusedelement(v = vs.110).aspx [ ^ ]。



要设置初始键盘焦点,您可以使用 http://msdn.microsoft.com/en-us/library/system.web.ui.control.focus%28v=vs.110%29。 aspx [ ^ ]。



要了解何时使用,请参阅上面的第一个链接。



-SA


请参考此链接我希望它会h elp you



https://stackoverflow.com/questions/19225443/set-focus-on-a-textbox-control-in-usercontrol-in-wpf [ ^ ]

how to set the focus to a usercontrol's textbox when the user control is added to a wpf window.

I have tried the below sample.

<stackpanel orientation="Vertical" focusmanager.focusedelement="{Binding ElementName=txt1}">

解决方案

WPF focusing is a pretty advanced topic. Please start here: http://msdn.microsoft.com/en-us/library/aa969768%28v=vs.110%29.aspx[^].

In most cases, you would need to set the logical focus. This is how: http://msdn.microsoft.com/en-us/library/system.windows.input.focusmanager.setfocusedelement(v=vs.110).aspx[^].

To set initial keyboard focus you can use http://msdn.microsoft.com/en-us/library/system.web.ui.control.focus%28v=vs.110%29.aspx[^].

To understand what to use when, please see the very first link above.

—SA


Please refer this link i hope it will help you

https://stackoverflow.com/questions/19225443/set-focus-on-a-textbox-control-in-usercontrol-in-wpf[^]


这篇关于添加到wpf窗口时如何将焦点设置到usercontrol的控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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