简体   繁体   中英

Extended combobox control

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.

  1. standart combobox

1. 标准组合框

  1. combobox open

2.组合框打开

  1. the most interresting - like filtered suggestions

3. 最有趣的 - 像过滤的建议


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

在此处输入图片说明

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();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM