Click here to Skip to main content
13,050,242 members (97,644 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Dear all,

It would be convenient for me to force a ComboBox to keep its popup expanded when it looses focus. Is there a way to do this. It doesn't heed to be ComboBox, but also SimpleComboBox, any UserControl based on any of them and any CustomControl which inherits from any of them.

Thanks in advance.
Posted 5-Apr-11 7:58am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

See the property ComboBox.StaysOpenOnEdit. Additionally, you can control the opened state by using ComboBox.IsDropDownOpen property, which is also a read-write property.

Alternatively, you can easily emulate similar or more complex behavior using the combination of TextBox and ListBox. Sometime ComboBox is not flexible enough; and some events are hard to trigger… Anyway, emulation of ComboBox behavior is a popular trick, not just in WPF.

dsnlkc 5-Apr-11 16:35pm
Good idea, but no. StaysOpenOnEdit property set to true keeps popup opened only when focus is transferred from the popup to ComboBox's TextBox.
Other idea is good, too, but when I use Listbox instead of popup I have following problem: ComboBox (or TextBox ListBox pair) will be part of UserControl. Popup (or Listbox) wont always be visible and when it is, it will exceed dimensions of the UserControl. That by itself is not a problem, but the UserControl will be put inside StackPanel which will be inside Scrollviewer. If I use TextBox ListBox pair, part of the ListBox that is outside of the UserControl will be clipped by the Scrollviewer. I had an idea to enlarge the UserControl (all the time or only when the ListBox becomes visible) so that whole ListBox can fit into it, but the ListBox will be collapsed most of the time and my designer says that solution isn't pretty enough.
I'm still exploring possibilities so I will take all the ideas (both yours and mine) under consideration.

In any case, thank you for your time and help. Happy coding.
SAKryukov 5-Apr-11 17:09pm
I'm pretty much sure you can get desired effect if you design and code it thoroughly.
About EditBox/ListBox pair I insist: it can be done the way the user cannot see the difference. You should handle many events though. Why am I so sure? 1) because internally, ComboBox is a pair of controls (windows based) supported via the common API, 2) because I've done something similar. It is solvable in this way, I'm sure.
dsnlkc 6-Apr-11 3:21am
OK, you being so sure casts some new light on the TextBox/ListBox pair approach. As I already said, I tried it and failed (which isn't big surprise because I'm new to WPF). To describe the problem depicted above, I created WPF project as simple as I could. Beside files created by Expression Blend automatically I created one user control: TextListPair. The content of MainWindow.xaml file is:

<pre lang="xml"><window xmlns="" xmlns:x="" xmlns:local="clr-namespace:clippingIsue2" x:class="clippingIsue2.MainWindow" x:name="Window" title="MainWindow" width="640" height="480">
<grid x:name="LayoutRoot">
<scrollviewer height="70" margin="135,121,244,0" verticalalignment="Top" removed="DarkGray" width="250">
<stackpanel verticalalignment="Top" removed="#FF07C81B">

and the content of TextListPair.xaml file is:

<pre lang="xml"><usercontrol xmlns="" xmlns:x="" xmlns:d="" xmlns:mc="" mc:ignorable="d" x:class="clippingIsue2.TextListPair" x:name="UserControl">
<grid x:name="LayoutRoot" removed="#FFBA0000">
<textbox margin="8" textwrapping="Wrap" text="TextBox"></textbox>
&lt;ListBox Height="100" Margin="8,0,8,-91.723" VerticalAlignment="Bottom" Background="#FF7C00C6"/&gt;

I did not make any changes to code-behind files. As you can see part of the Listbox is clipped by Scrollviewer. If there was ComboBox instead of TextListPair, its popup wouldn't be clipped. It would exceed dimensions of the Scrollviewer.

So, how can I do that with Listbox?
Alternatively, solution where the Listbox doesn't exceed dimensions of Scrollviewer, but the Scrollviewer allows scrolling so that user can scroll down to see the rest of the Listbox, would be satisfactory, too.

Thanks in advance.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 5 Apr 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100