Is it possible to have a different ComboBox Popup part depending on the Popup direction? RRS feed

  • Question

  • I'm styling the combo box and I'd like to change the drop down visually depending on the Popup direction...  if it pops down, then certain elements will be visible to change look, while if it drops up, other elements will be visible instead.

    Is this possible?


    Thursday, March 22, 2012 4:26 PM

All replies

  • One possible way would be to change the ItemsSource on your ComboBox so the correct elements are visible. Another way would be to change the Visibility on certain items based on certain criteria. There are certainly others, depending on your style and how you've got things laid out so far. How are you determining the direction?

    Thursday, March 22, 2012 6:17 PM
  • I guess that's the trick--what property trigger (if any) can be set so if the menu pops upwards, I can set the visibility=1 for GridA and if it pops downwards, set the visibility=1 for GridB...  it's just the layout of the Popup itself, I don't want to change the ItemsPresenter within.

    Right now I have GridA and GridB (with vector artwork inside) invisible in my ComboBox Template under PART_Popup.  It would be great if I could setup a trigger, but not sure if that's possible...  


    Thursday, March 22, 2012 6:25 PM
  • What platform (WPF/Silverlight/WP7)?

    Are you controlling the popup direction yourself or are you trying to grab the direction (i.e., you don't know it beforehand)?

    Thursday, March 22, 2012 6:27 PM
  • Ah yes, some more details would help, ha ha, Sorry Brian.

    It's a WPF application. 

    I'm not setting the popup direction, I'm letting the system determine it depending on if the popup doesn't have enough clearance on the bottom (if the combobox is too low on the screen).  As a result, i want to accomodate a change in look should the popup pop open upwards instead of the customary downwards.  So no, I don't know which direction the popup will go--it could go either depending on layout.


    Thursday, March 22, 2012 6:30 PM
  • From the investigation I've done, I think the answer is "you can't." I could be wrong, but I couldn't see how to do it.

    The first thing I tried was a two-way binding with the Placement property. However, Placement isn't a hard-and-fast rule, it's just a guideline. For example, having a Placement of "Bottom" will try to put the popup on the bottom of the target, but failing that it'll just put the popup where it fits.

    Popup has an Opened event that fires when it gets opened. I was thinking that you'd be able to look at the PlacementTarget and Horizontal/VerticalOffset properties. Unfortunately, those are all null in the case I tried; when the values are null, the system goes with the defaults.

    The end result is I don't think I you can do this. You can try your best to set things, but in the end the system might overrule you if you created an invalid set of values, and that would break your code/design. Hope this information helps somewhat, let me know if you find out anything else.

    Friday, March 23, 2012 3:22 PM
  • I tried similar approaches without luck.  Thanks for giving it a stab, Brian. I'll let you know if I do indeed find a way.


    Friday, March 23, 2012 3:41 PM