如何在WPF中向可编辑的ComboBox添加焦点样式 [英] How to add a focus style to an editable ComboBox in WPF
问题描述
我一直在查看以下示例如何设置 ComboBox
的样式,但是在进入可编辑组合框时,我无法创建焦点效果。每当 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.
基本问题是,每当我进入编辑模式时,它不是周围的 ComboBox
焦点,但文本子组件和我一直无法创建触发器
在文本组件修改 ComboBox
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.
我试过添加 ControlTemplate
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.
推荐答案
将IsKeyboardFocusWithin绑定到IsDropDownOpen
Bind IsKeyboardFocusWithin to IsDropDownOpen
<ComboBox ItemsSource="{Binding SortedItems}" StaysOpenOnEdit="True"
IsDropDownOpen="{Binding IsKeyboardFocusWithin,
RelativeSource={RelativeSource Self},
Mode=OneWay}">
</ComboBox>
这篇关于如何在WPF中向可编辑的ComboBox添加焦点样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!