Prerequisites
Now, let's get started with the following steps:
Step 1 - Create Windows Universal Project
Open Visual Studio 2015 and click File -> New -> Project Option for New Universal App.
Step 2 - Giving the Project Name
Then, New Project Window will open. There, you can select Installed -> Template -> Visual C# -> Windows -> Universal and select "Blank App (Universal Windows)".
Type the project name, such as ComboApp and click the OK button.
Step 3 - Setting the platform Versions
Here, we choose the Target Version and Minimum Version for our Universal Windows application. Click OK.
Step 4 - Choose Designer Window
Now, go to the Solution Explorer and open the MainPage.xaml for design.
Step 5 - Designing the App
In the MainPage.xaml designing page, drag the Combo Box button control from the tool box. Then, go to the Properties window and click Items.
Next, choose ComboBoxitem and click Add.
Now, add the ComboBoxItems that you required.
Next, choose Common -> Content from the properties window and change the item name.
Step 6 - Add the Coding
To add the coding, double click on the Combo box and add the below mentioned source code.
- private void combobox_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (combobox == null) return;
- var combo = (ComboBox) sender;
- var item = (ComboBoxItem) combo.SelectedItem;
- textcombo.Text = "The selected item is " + item.Content.ToString();
- }
Add the following to the Header file.
- using Windows.UI.Xaml.Controls;
Step 7 - Run the Application
Now, we are ready to run our Project. Click on the Local Machine icon at top ribbon for running the application.
Output Conclusion - I hope you understood Combo Box button control in Universal Window and how to run it.