编辑时禁用WPF ComboBox DropDown [英] Disable WPF ComboBox DropDown while editing

查看:183
本文介绍了编辑时禁用WPF ComboBox DropDown的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





当属性isEditable设置为true时,我想禁用组合框的下拉列表,反之亦然。因此我创建了一个继承自ComboBox的自定义控件。



将标准控件模板从ComboBox粘贴到Generic.xaml并启动应用程序后,只有当我用鼠标悬停时才能看到组合框。到目前为止,我没有在控件模板中进行任何更改。



1.难道不能显示为普通的ComboBox吗?



2.这是在编辑时锁定DropDown的正确方法是什么?

Hi,

i want to disable the dropdown of a combobox, when the property "isEditable" is set to true and vice versa. Therefore i''ve created a custom control which inherits from ComboBox.

After pasting the standard control template from the ComboBox into the Generic.xaml and starting the app, the combobox is only visible when i hover over with the mouse. I didn''t change anything in the control template so far.

1. Shouldn''t it be displayed as a normal ComboBox?

2. Is this the right approach to lock the DropDown while editing?

<Trigger Property="ComboBox.IsEditable" Value="True">
  <Setter Property="UIElement.IsEnabled" Value="False" />
</Trigger>

推荐答案

这是我不清楚你想要达到的目标。



但是如果你想在 IsEditable 设置为True并在 IsEditable 为False时显示,然后您可以检查此代码(添加到 ControlTemplate.Triggers ):



It is not clear for me what you are trying to achieve.

But if you want dropdown not to be shown when IsEditable is set to True and appear when IsEditable is False, then you can check this code (add to ControlTemplate.Triggers):

<MultiTrigger>
    <MultiTrigger.Conditions>
        <Condition Property="IsEditable" Value="True"></Condition>
        <Condition  Property="IsDropDownOpen" Value="True"></Condition>
    </MultiTrigger.Conditions>
    <Setter TargetName="Popup" Property="IsOpen" Value="False"></Setter>
</MultiTrigger>
<Trigger Property="ComboBox.IsEditable" Value="True">
    <Setter TargetName="ToggleButton" Property="IsEnabled" Value="False" />
</Trigger>





如果用户单击切换按钮或按Alt + UpArrow / DownArrow,则可以显示下拉菜单。所以这里我们禁用/启用切换按钮并使弹出显示逻辑依赖于 IsEditable


这篇关于编辑时禁用WPF ComboBox DropDown的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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