简体   繁体   中英

How do I set a default value to a combobox?

I have a small bit of code for a combobox, and I want the default selection to be "kids". How would I do this?

<ComboBox Margin="10" DockPanel.Dock="Top" x:Name="categoryBox" FontSize="20">
                <ComboBox.Items>
                    <ComboBoxItem>Kids</ComboBoxItem>
                    <ComboBoxItem>Films</ComboBoxItem>
                    <ComboBoxItem>Foods</ComboBoxItem>
                </ComboBox.Items>

Just set the property SelectedIndex to 0.

<ComboBox Margin="10" DockPanel.Dock="Top" x:Name="categoryBox" FontSize="20" SelectedIndex = "0">
                    <ComboBox.Items>
                        <ComboBoxItem>Kids</ComboBoxItem>
                        <ComboBoxItem>Films</ComboBoxItem>
                        <ComboBoxItem>Foods</ComboBoxItem>
                    </ComboBox.Items>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM