开发者

How to set the focus on a user control item in WPF?

开发者 https://www.devze.com 2023-03-25 01:30 出处:网络
I have a WPF app that uses different instances of a User Control; when the user clicks a button on the mai开发者_StackOverflow中文版n window I need to set the focus on the textbox inside the currently

I have a WPF app that uses different instances of a User Control; when the user clicks a button on the mai开发者_StackOverflow中文版n window I need to set the focus on the textbox inside the currently active instance of the user control.

Which is the best way to set the focus on that child item?


child.Focus();

or

VisualTreeHelper.GetChild(parent, 0).Focus(); // you might want to test it for nulls
0

精彩评论

暂无评论...
验证码 换一张
取 消