Autocomplete textbox in WPF (well, almost)
Autocomplete textbox is missing control in WPF 3.0 and WPF 3.5. Is it true? Actually, WPF is very extensible language, thus it is almost work nothing to build user control, derrived from TextBox to achive autocomplete functionality. But are we really have to do it? Let’s try to understand which control can provide us with similar functionality. I’m beting on ComboBox.
<
ComboBox>
<TextBlock>Hello</TextBlock>
<TextBlock>World</TextBlock>
<TextBlock>This</TextBlock>
<TextBlock>is</TextBlock>
<TextBlock>Autocomplete</TextBlock>
<TextBlock>Textbox</TextBlock>
</ComboBox>
Now we have to make the combobox editable. So, let’s set IsEditable property to True. Ok, I can write, but can not select. ComboBox control provides us with option to choose items by typing its values. This works only when the ComboBox is opened. So we have to force the ComboBox to open its items and leave them opened while typing without pressing the arrow sign at the right. If I’ll bet on IsDropDownOpen property, I’ll be wrong, ‘cos I not need to see itesm, I want only select them. Another property looks interesting is IsTextSearchEnabled. Let’s see MSDN to understand what this property do… “Enables a user to quickly access items in a set by typing prefixes of strings”. Wow, that’s exactly what I need. But… what the default value? It’s True, so I’m not really need to set it. Let’s see, how can I force items to be opened while typing. Got it – StaysOpenOnEdit property.
Now, if I’ll put IsEditable=”True” StaysOpenOnEdit=”True” I’ll make my ComboBox to accept keystrokes to choose items without openning items panel. And that exactly what I need. So, now ComboBox with those two properties set to True converts into regular TextBox with autocomplition functionality. The only thing you should do (if you really want to), is to change control template to remove triangle button at right.
October 28th, 2007 · Comments (5)
5 Responses to “Autocomplete textbox in WPF (well, almost)”
Leave a Reply
Discover other tags
My tools
- .NET Framework Detector
- Duplicate images finder
- Exchange Security Policy for Windows Mobile Devices Fix
- Gas Price Windows Vista SideBar gadget
- Israel Traffic Information Windows Vista SideBar gadget
- Localization fix for SAP ES Explorer for Visual Studio
- LocTester
- RTL and LTR in Windows Live Writer
- Silverlight controls library
- Snipping tool integration plugin for WLW
- USB FM receiver library
- Vista Battery Saver
- WebCam control for WPF
- Windows Live SkyDrive attachment for Windows Live Writer
- Wireless Migrator
- WPF Virtual Keyboard




January 1st, 2009 at 12:25 am
Good one but what if my list contains millions of records & i just need to display, let say, 10 of them at a time. Might need to write some code for that ?
January 1st, 2009 at 12:25 am
Autocomplete textbox is missing control in WPF 3.0 and WPF 3.5 . Is it true? Actually, WPF is very extensible
January 1st, 2009 at 12:25 am
Very nice.
January 1st, 2009 at 12:25 am
Pingback from Web 2.0 – Social Media – Internet News – Blogging » Autocomplete textbox in WPF (well, almost)
February 3rd, 2012 at 1:22 am
Great one!
Much simpler and sufficient than adding user control, libs, etc…!
Cheers
Tobias