Using the StackPanel as ItemsPanelTemplate for ComBoBox occured strange behavior

Xie Steven 781 Reputation points

As we all know, the UWP ComboBox control uses the CarouselPanel as its ItemsPanelTemplate. With it, the ComboBox's dropdown-list will cyclic scroll when the app runs on the tablet mode. But we don't want the cyclic scrolling on tablet mode.

So, we use the StaclPanel as its ItemsPanelTemplate. (Here, we do not think about the perfamce issue when using the StackPanel.)

Then, the strange behavior occurred. Once I set an item as the default selected item for the ComBoBox, the first item in the dropdown-list cannot be selected.

See the code sample:

<ComboBox ItemsSource="{x:Bind tests, Mode=OneWay}" SelectedItem="{x:Bind SelectedTest, Mode=TwoWay}">  
                <DataTemplate x:DataType="local:Test">  
                    <TextBlock Text="{x:Bind name, Mode=OneWay}"></TextBlock>  
                    <StackPanel Orientation="Vertical"></StackPanel>  

public sealed partial class MainPage : Page,INotifyPropertyChanged  
        ObservableCollection<Test> tests { get; set; } = new ObservableCollection<Test>();  
        private Test selectedTest;  
        public event PropertyChangedEventHandler PropertyChanged;  
        public Test SelectedTest  
                return this.selectedTest;  
                if (this.selectedTest != value)  
                    this.selectedTest = value;  
                    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("SelectedTest"));  
        public MainPage()  
            for (int i=0;i<10;i++)  
                tests.Add(new Test() {name="name " +i });  
            this.SelectedTest = this.tests[0];  
    public class Test  
        public string name { get; set; }  
Universal Windows Platform (UWP)
0 comments No comments
{count} votes

Accepted answer
  1. Fay Wang - MSFT 5,151 Reputation points


    ​Welcome to our Microsoft Q&A platform!

    This is an expected bebavior. Please refer to the Note part of this document, it mentions:

    > ComboBox uses a CarouselPanel as its ItemsPanel. Using a different panel as the ItemsPanel is not supported and might result in undesired behavior.

    So please don't use StackPanel as its ItemsPanel but CarouselPanel.

0 additional answers

Sort by: Most helpful