I have ComboBoxa IsEditableset True, so I can enter TextBoxinto ComboBox. Now I want to open DropDownList, so I created for it Attached Property:
Public Shared Function GetShowDropDown(obj As DependencyObject) As Boolean
Return obj.GetValue(IsDigitOnlyProperty)
End Function
Public Shared Sub SetShowDropDown(obj As DependencyObject, value As Boolean)
obj.SetValue(IsDigitOnlyProperty, value)
End Sub
Public Shared ReadOnly ShowDropDownProperty As DependencyProperty = DependencyProperty.RegisterAttached("ShowDropDown", GetType(Boolean), GetType(ControlBehaviour), New UIPropertyMetadata(False, AddressOf OnShowDropDown))
Private Shared Sub OnShowDropDown(sender As Object, e As DependencyPropertyChangedEventArgs)
Dim comboBox As ComboBox = sender
Dim showDropDown As Boolean = e.NewValue
If showDropDown Then
AddHandler comboBox.PreviewKeyUp, AddressOf DoShowDropDown
Else
RemoveHandler comboBox.PreviewKeyUp, AddressOf DoShowDropDown
End If
End Sub
Private Shared Sub DoShowDropDown(sender As Object, e As KeyEventArgs)
Dim comboBox As ComboBox = sender
If comboBox.Text.Length > 0 Then
comboBox.IsDropDownOpen = True
Else
comboBox.IsDropDownOpen = False
End If
End Sub
Whenever I type ComboBox, a DropDownList opens, but there is 1 drawback. Let me explain this as follows:
- There are several elements (lines) in the list, of which 1 is “Test”.
- If I type “T” in
TextBox ComboBox, “est” is added after “T” to show “Test”. - ""
TextBox . , "e", "Test" "e" TextBox ( , - .
, TextBox, , "" . , "". , .

, , - , 2- TextBox, , .
- , Enter, , DropDown.