Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

1 solution

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.

—SA
 
Share this answer
 
v2
Comments
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.
Sergey Alexandrovich Kryukov 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.
--SA
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="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 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">
<local:textlistpair></local:textlistpair>
</stackpanel>
</scrollviewer>
</grid>
</window></pre>

and the content of TextListPair.xaml file is:

<pre lang="xml"><usercontrol xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 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;
</grid>
</usercontrol></pre>

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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900