ComboBox keep it OPEN

378 views
Skip to first unread message

Marlon Grech

unread,
Feb 12, 2008, 5:56:13 PM2/12/08
to wpf-di...@googlegroups.com
Hey guys,

As you all know (I guess) I use a ComboBox for the DatePicker default template. I want that when the user selects a date from the listbox (which is an item in the combobox) the combobox does not close.... Is there an easy way to do this.... I tried it but without any sucess.... My next try will be to write my own combobox (a hacked one) that would support this

Thanks

--
Regards
Marlon
Blog - http://marlongrech.wordpress.com/
WPF Controls Library - http://www.codeplex.com/avaloncontrolslib

Karl Shifflett

unread,
Feb 12, 2008, 6:00:01 PM2/12/08
to wpf-di...@googlegroups.com
A combobox that stays open smells like a listbox.

________________________________

winmail.dat

Dr. WPF

unread,
Feb 13, 2008, 2:22:44 AM2/13/08
to wpf-di...@googlegroups.com

Hey Marlon,

The ComboBox class does some magic to keep several properties in sync and to make sure the popup is closed when a selection is made.

Rather than using a ComboBox, you might consider exposing an IsDropDownOpen property on your control and then just using a Popup in your style.  The IsOpen property of the Popup can then be bound to the IsDropDownOpen property of your DatePicker.

This is similar to the approach used by ComboBox itself, but it gives you full control over when the popup is opened or closed.  And if someone chooses to retemplate the control without a Popup, everything still works great.

I've pasted part of a (really old) template for one of my controls of yor.  Apologies for the outdated snippet...  the approach should still be valid.  (This was from the days when every control in the framework was composed with dozens of elements...  yikes! what a waste!...  prior to the bright idea of introducing the ButtonChrome theme class.  And evidently I was really into blue at the time.  :-s)

Cheers,
-dw

<Border

> />>


Dr. WPF - Online Office at http://www.drwpf.com/blog/

Background="{TemplateBinding Background}"     BorderThickness="{TemplateBinding BorderThickness}"     BorderBrush="{TemplateBinding BorderBrush}">
  <Grid>
    <Rectangle x:Name="R1" Margin
="0,0,0,0"
       
HorizontalAlignment="Right" Width="1" 
        Fill
="CornflowerBlue"
/>
    <Rectangle
x:Name="B1" Margin
="0,0,1,0"
       
VerticalAlignment="Bottom" Height="1"
        Fill
="CornflowerBlue"
/>
    <Rectangle
x:Name="L1" Margin
="0,0,1,1"
       
HorizontalAlignment="Left" Width="1" 
        Fill
="CornflowerBlue"
/>
    <Rectangle
x:Name="T1" Margin
="1,0,1,1"
       
VerticalAlignment="Top" Height="1" 
        
Fill="CornflowerBlue"
/>
    <Rectangle
x:Name="R2" Margin
="1,1,1,1"
       
HorizontalAlignment="Right" Width="1"         Fill="Navy"
/>
    <Rectangle
x:Name="B2" Margin
="1,1,2,1"
       
VerticalAlignment="Bottom" Height="1"         Fill="Navy"
/>
    <Rectangle
x:Name="L2" Margin
="1,1,2,2" 
        
HorizontalAlignment="Left" Width="1"         Fill="White"
/>    <Rectangle x:Name="T2" Margin="2,1,2,2"
       
VerticalAlignment="Top" Height="1"
       
Fill="White"
/>
    <DockPanel
Margin="2"
>          . . . (snip)    </DockPanel>
    <ToggleButton
x:Name="DropDownButton" Margin
="2" 
        
MinWidth="0" MinHeight="0" Width="Auto" Focusable
="False" 
        
Style
="{DynamicResource DropDownButtonStyle}"         IsChecked="{Binding Path=IsDropDownOpen, 
           
Mode=TwoWay, RelativeSource=/TemplatedParent}"         ClickMode="Press" />
    <Popup
Placement="Bottom" Focusable
="False"        IsOpen="{Binding Path=IsDropDownOpen,
            RelativeSource=/TemplatedParent}"
>
      <Border
Background
="{TemplateBinding Background}"
         
BorderThickness="1" BorderBrush="CornflowerBlue"
>
        <jwc:DateTimeRangePicker
           
Style="{StaticResource DateTimeRangePickerStyle}"
/>
      </Border>
    </Popup>
  </Grid>
</Border>

Dr. WPF

unread,
Feb 13, 2008, 2:28:28 AM2/13/08
to wpf-di...@googlegroups.com

Not sure what happened with the formatting of the snippet in that last mail... here it is in black and white:

Quoting "Dr. WPF" <a...@drwpf.com>:

>
>
>    Hey Marlon,
>
>    The ComboBox class does some magic to keep several properties in
> sync and to make sure the popup is closed when a selection is made.
>
>    Rather than using a ComboBox, you might consider exposing an
> IsDropDownOpen property on your control and then just using a Popup in
> your style.  The IsOpen property of the Popup can then be bound to the
> IsDropDownOpen property of your DatePicker.
>
>    This is similar to the approach used by ComboBox itself, but it
> gives you full control over when the popup is opened or closed.  And
> if someone chooses to retemplate the control without a Popup,
> everything still works great.
>

>    I've pasted part of a /(really old)/ template for one of my

Dr. WPF

unread,
Feb 13, 2008, 2:33:49 AM2/13/08
to wpf-di...@googlegroups.com

Oh crap!  And update the RelativeSource references to use {RelativeSource TemplatedParent} rather than "\TemplatedParent"... that code is older than I thought (~ 4 yrs).

Reply all
Reply to author
Forward
0 new messages