Turning off ComboBox loop scroll

99封情书 提交于 2019-12-07 21:37:34

问题


I have a ComboBox to let the user choose from a list, but when the list gets long enough it begins to automatically wrap around. For example, if the user scrolls far enough down they'll reach the end of the list and then find the top of the list just after a single blank row. The drop down selection list never really ends, it just keeps looping forever.

How can I remove this looping scroll feature so the user just reaches the end of list?

My code:

<ComboBox Name="listSelect" ItemsSource="{Binding DataInstance.ItemList}">
    <ComboBox.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding ItemNumber, Mode=OneWay}" />
        </DataTemplate>
    </ComboBox.ItemTemplate>
</ComboBox>

回答1:


Possible solution from this article: http://netitude.bc3tech.net/2013/04/12/windows-8s-combobox-and-the-carouselpanel/

Set this to your ComboBox control, this should overwrite the default panel:

 <ComboBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Vertical" />
                </ItemsPanelTemplate>
 </ComboBox.ItemsPanel>

This is to edit the panel template, so your final code will be:

<ComboBox Name="listSelect" ItemsSource="{Binding DataInstance.ItemList}">
    <ComboBox.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding ItemNumber, Mode=OneWay}" />
        </DataTemplate>
    </ComboBox.ItemTemplate>
     <ComboBox.ItemsPanel>
                    <ItemsPanelTemplate>
                        <StackPanel Orientation="Vertical" />
                    </ItemsPanelTemplate>
     </ComboBox.ItemsPanel>
</ComboBox> 


来源:https://stackoverflow.com/questions/37880522/turning-off-combobox-loop-scroll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!