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 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 a Blank App (Universal Windows).
Type Project Name as ListBoxApp and click OK.
Step 3 - Setting the platform Versions
Here, we choose the Target Version and Minimum Version for our Universal Windows application and click OK.
Step 4 - Choose Designer Window
Now, we 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 ListBox button control from the tool box and change the name as listboxcontrol. Then, go to the Properties window and click items.
Next, choose the ListBox item and click Add.
Next, choose Common -> Content from the properties window and change the item name.
Likewise, you add the required ListBox items and click OK.
Then, add the Textblock control and change the name as textblockcontrol.
Step 6 - Add the Coding
To add the coding, double click on the ListBox. Then, add the mentioned source code.
- private void listboxcontrol_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- var selected = listboxcontrol.Items.Cast < ListBoxItem > ().Where(p => p.IsSelected).Select(t => t.Content.ToString()).ToArray();
- textblockcontrol.Text = "The selected List Box items are " + string.Join(", ", selected);
- }
Step 7 - Run the Application
Now, we are ready to run our Project. So, click Local Machine for running the Application.
Output Conclusion
I hope you understood ListBox button control in Universal Windows, and how to run it.