如何使两个控件显示为焦点?
我正在尝试编写一个自定义控件,其模板内有一个 TextBox 和一个 ListBox。 但我发现,当我在 TextBox 中输入文本(因此 TextBox 具有焦点)时,ListBox 显示为未聚焦。这使得我的控件看起来像两个不同的控件。
我在 MSDN 上读到,在 WPF 中有一个名为 FocusScope 的东西,但我没有成功使用它。
所以我的问题是,当其中一个控件具有键盘焦点时,如何使 ListBox 和 TextBox 控件都显示为焦点?
I'm trying to write a custom control, that have a TextBox and a ListBox inside it's template.
But I've found that when I entering a text in the TextBox (so TextBox has focus), ListBox appears as not focused. This makes my control looks like two different controls.
I've read at MSDN that in the WPF there is something called FocusScope but I didn't succeed with it.
So my question is how can I make both ListBox and TextBox controls appear as focused when one of them has keyboard focus within?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将
IsFocusScope
属性设置为周围的 Panel(此处:StackPanel):ListBox 和 TextBox 在聚焦方面被放在一起处理
Set the
IsFocusScope
Property to the surrounding Panel (here: StackPanel):The ListBox and the TextBox are treated together in regards of being focussed