Reputation: 9446
I need a control which extremelly looks like combobox from win run
window.
My question is is it a standart combobox control
with specific settings or I have to create a custom control
in order to achieve this appearance and behavior ?
I'm interested in appearance and behaviour next to the third image - like filtered suggestions which shown as listbox
in a popup
after pressing a key.
UPDATED!
Is it a standard combobox control ? As you can see in the attached gif below when I start inputting something combobox looks like a textbox with popup window under it which contains filtered items. Like a sort of mix between textbox, combobox and popup window with listbox
Upvotes: 0
Views: 1231
Reputation: 2363
This is already built into the ComboBox
. Here is an example:
<ComboBox
IsEditable="True" //This enables to enter values that don't belong to the ItemsSource collection
IsTextSearchEnabled="True" //this allows you to have "suggestions" when you enter text
IsTextSearchCaseSensitive="False"
StaysOpenOnEdit="True"
Text="{Binding NameOnViewModel}"
TextSearch.TextPath="NameOnChildItems" //this is the property on which combobox will filter the items
ItemsSource="{Binding Items}" //collection of your items to search on
ItemTemplate="{StaticResource DataTemplate}" />//this can be replaced with DisplayMemeberPath="PropertyName"
Note:
This example was taken from this SO post.
EDIT
In case you want the popup to open when you are typing in the values then this could be of help:
</ComboBox.Style>
<Style TargetType="{x:Type ComboBox}">
<Style.Triggers>
<Trigger Property="IsKeyboardFocusWithin" Value="True">//you can also use a different event if this one doesn't suit your needs.
<Setter Property="IsDropDownOpen" Value="true" />
</Trigger>
</Style.Triggers>
</Style>
</ComboBox.Style>
EDIT 2
For filtering of the VISIBLE objects in the drop down list of your combobox then use the key down event and filter it in the event handler like so:
private void cmbKeyDown(object sender, KeyEventArgs e)
{
string temp = ((ComboBox)sender).Text;
var newList = MyList.Where(x => x.Name.Contains(temp));
MyList = newList.ToList();
}
Upvotes: 1