locked
WinRT ComboBox opens to middle of list when nothing selected

    Question

  • So one particular behavior of the XAML combobox in WinRT is causing me a huge headache, because my client sees it as a defect, and doesn't care if it's the behavior of the control, he wants it changed. However, I cannot find anything that tells how to change it. The behavior I'm speaking of is that when nothing is selected the ComboBox popup opens displaying the ItemsSource in the middle of the list. I have a sorted list of countries, with the exception of US, UK, CAN being at the top. These 3 items are the most often selected items and the client wants them on top rather than having to scroll through the list to find them. That's easy enough, but because the list opens in the middle, you still have to scroll quite a bit to get to them. Is there some property I'm missing that turns this behavior off? I was able to finally convince them that the CarouselPanel wasn't a defect, but this one isn't going to fly.

    So this combobox is databound through a ViewModel. in this instance, the ViewModel has no value (it is an empty string) for that particular property and so the Combobox shows empty, which is fine and desirable. When you click on the Combobox to select a value, it displays the list in the middle of the available values. this is the behavior that is undesirable. it should be showing the 1st value in the list at the top!

    Thanks in advance!

    Wednesday, October 01, 2014 10:16 PM

All replies

  • Wouldn't it be easiest to specify the selectedindex =0 to open at the top?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Thursday, October 02, 2014 1:58 PM
    Moderator
  • If I did that, would it not then select even if the field already has a value. like I said, this is databound. the data coming from the Viewmodel may be empty or may have a value. if it has a value, everything works fine. if I set it to index of 0, would it blank out those values?  And would this be done in the ViewModel? if so, how?
    • Edited by Shaggy13spe Thursday, October 02, 2014 3:58 PM
    Thursday, October 02, 2014 3:57 PM
  • I tried this and it has the undesirable effect of selecting the first item. I want the combo to be blank if the there isn't already data in the viewmodel that it is bound to because it lets the user know they need to pick something. if I default it, they could ignore it. This is business critical not to allow as it deals with immigration data and the US government. The limitations and oddball behaviors of the WinRT XAML controls bites me yet again.
    Thursday, October 02, 2014 4:45 PM
  • Hi, Shaggy13spe.

    It's normal behavior of combobox. You can set your fist element from list (itemsSource) to selectedItem (selectedIndex) - it's to normal behavior (I do it in all projects), because if user want to change it - he change it, but if user from first country - he need not to change anything.

    Set to selectedItem your first element from list and all will be alright.

    Regards, Nikita.

    Thursday, October 02, 2014 6:16 PM
  • Set the first item to blank and use validation to ensure that it's set to something else.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Thursday, October 02, 2014 7:19 PM
    Moderator