如何向 WPF 中的可编辑组合框添加焦点样式
我一直在查看以下关于如何设置 ComboBox
样式的示例,但在进入可编辑组合框时我无法创建焦点效果。每当 ComboBox
接收焦点时,它应该进入编辑模式,并且组件应该具有焦点样式。
基本问题是,每当我进入编辑模式时,实际上具有焦点的不是周围的 ComboBox,而是文本子组件,而我无法创建 Trigger< /code> 在文本组件上,它修改了 ComboBox
的边框样式,因为我不知道如何从触发器引用父组件。
我尝试在 TextBox
或样式触发器上添加 ControlTemplate
Trigger
。我尝试通过名称或使用 TemplateBinding
选项来引用 ComboBox
,但没有成功。一个简单的例子将非常感激。
I've been looking at the following example on how to style the ComboBox
, but I haven't been able to create a focus effect when going into an editable combo box. Whenever the ComboBox
receives focus, it should go into edit mode and the component should have a focus style.
The basic problem is that whenever I go into the edit mode, it's not the surrounding ComboBox
which actually has the focus, but the text subcomponent and I haven't been able to create a Trigger
on the text component which modifies the ComboBox
's border style since I don't know how to refer to the parent component from the trigger.
I've tried adding ControlTemplate
Trigger
on the TextBox
, or style trigger. I've tried to refer to the ComboBox
by name or by using the TemplateBinding
option, but without any luck. A simple example would be very appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将 IsKeyboardFocusWithin 绑定到 IsDropDownOpen
Bind IsKeyboardFocusWithin to IsDropDownOpen
在其
Gotfocus
中设置组合框的边框画笔,并使其在失去焦点时透明:Set the border brush of combobox in its
Gotfocus
and make it transparent in lost focus: