WPF: Editable ComboBox that drops up?

后端 未结 1 683
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-25 05:02

Im trying to create a ComboBox thats both editable and drops up instead of down. The menu should also open when pressing the up-arrow-key (down by default).

I have tried

相关标签:
1条回答
  • 2021-01-25 05:52

    The default ControlTemplate is not for the IsEditable = true variety, but the style contains a trigger that changes it when IsEditable is set:

    <Style.Triggers>
        <Trigger Property="IsEditable" Value="true">
            <Setter Property="BorderBrush" Value="{StaticResource TextBoxBorder}"/>
            <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
            <Setter Property="IsTabStop" Value="false"/>
            <Setter Property="Padding" Value="3"/>
            <Setter Property="Template" Value="{StaticResource ComboBoxEditableTemplate}"/>
        </Trigger>
    </Style.Triggers>
    

    It changes it to another ControlTemplate where the relevant part is the popup:

    <Popup x:Name="PART_Popup" 
           AllowsTransparency="true" 
           Grid.ColumnSpan="2" 
           IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" 
           Placement="Bottom">
    ...
    </Popup>
    

    I think you should just be able to change the Placement property to Top.

    0 讨论(0)
提交回复
热议问题