question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposal: Allow `ComboBox` `IsTextSearchEnabled` when `ItemTemplate` provided

See original GitHub issue

Proposal: Allow ComboBox IsTextSearchEnabled when ItemTemplate provided

Summary

IsTextSearchEnabled allows users to type characters into a ComboBox and jump to the entry starting with that letter. However, this only works if the ItemsSource is a list of strings (understandably so). It would be nice to provide some kind of API to enable this feature when the ItemsSource is a custom object and the ComboBoxItems are presented as more complex views of the bound item.

Example

Rationale

  • Customizing the appearance of ComboBox items is not uncommon. In the example above, all I’ve added is an icon.
  • TextSearch is a very useful feature. Users can get confused if some ComboBoxes have it enabled (because they are bound to strings) and others don’t.
  • The developer could try to implement this manually, but then they are at risk of implementing it slightly differently. A first party solution would be preferred.

Scope

Capability Priority
This proposal will allow developers to accomplish W Must
This proposal will allow end users to accomplish X Should
This proposal will allow developers to accomplish Y Could
This proposal will allow end users to accomplish Z Won’t

Important Notes

Example: Windows Terminal binds ComboBox.ItemsSource to the settings model as such:

                    <ComboBox x:Name="DefaultProfile"
                              ItemsSource="{x:Bind State.Settings.AllProfiles, Mode=OneWay}"
                              SelectedItem="{x:Bind CurrentDefaultProfile, Mode=TwoWay}"
                              Style="{StaticResource ComboBoxSettingStyle}">
                        <ComboBox.ItemTemplate>
                            <DataTemplate x:DataType="SettingsModel:Profile">
                                <Grid HorizontalAlignment="Stretch" ColumnSpacing="8">

                                    <Grid.ColumnDefinitions>
                                        <!-- icon -->
                                        <ColumnDefinition Width="16"/>
                                        <!-- profile name -->
                                        <ColumnDefinition Width="Auto"/>
                                    </Grid.ColumnDefinitions>

                                    <IconSourceElement
                                    Grid.Column="0"
                                    Width="16"
                                    Height="16"
                                    IconSource="{x:Bind Icon,
                                                        Mode=OneWay,
                                                        Converter={StaticResource IconSourceConverter}}"/>

                                    <TextBlock Grid.Column="1"
                                           Text="{x:Bind Name}"/>

                                </Grid>
                            </DataTemplate>
                        </ComboBox.ItemTemplate>
                    </ComboBox>

where State.Settings.AllProfiles is an observable vector of profile objects. All we’re doing in this template is adding an icon. Binding to Profile objects allows us to bind SelectedItem and have this work fairly straightforward with little modifications.

Open Questions

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
carlos-zamoracommented, Feb 18, 2021

Aha! Turns out you need the Windows.Foundation.IStringable interface. Then it works!

I guess the only ask I have here is to please include this in the docs. Thanks for the quick response folks! Closing!

1reaction
carlos-zamoracommented, Feb 18, 2021

Yup. Dustin and I were chatting on teams haha

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to do text search in DropDown of ComboBox with ...
Set the IsTextSearchEnabled property to true and the TextSearch.TextPath attached property to either "LastName" or"FirstName" or whatever ...
Read more >
ComboBox.IsTextSearchEnabled Property - UWP
Gets or sets a value that specifies whether a user can jump to a value by typing.
Read more >
Multiple Selection - WPF ComboBox - Documentation - Telerik
To enable the multiple selection, set the AllowMultipleSelection property to True as shown in Example 1. Example 1: Allowing multiple selection. XAML.
Read more >
XamComboEditor with drop down grid
Hi. In the winforms version of your combobox there is a nice feature to be able to bind a dataset to the combobox...
Read more >
The ComboBox control
A complete walkthrough of how and when to use the WPF ComboBox control. ... Let's try making a slightly more sophisticated list of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found