MainPage.xaml
<Page
x:Class="UniversalAppTutorials.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UniversalAppTutorials"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<StackPanel Margin="50" Orientation="Vertical">
<TextBlock
x:Name="textblock1"
Text="Choose your favorite colors."
/>
<CheckBox x:Name="checkbox_1" Content="Red"/>
<CheckBox x:Name="checkbox_2" Content="Green"/>
<CheckBox x:Name="checkbox_3" Content="Blue"/>
<CheckBox x:Name="checkbox_4" Content="Yellow"/>
<CheckBox x:Name="checkbox_5" Content="Magenta"/>
<CheckBox x:Name="checkbox_6" Content="Pink"/>
<CheckBox x:Name="checkbox_7" Content="Orange"/>
<Button
x:Name="button_1"
Content="Show Result"
Click="button1_click"
/>
<TextBlock
x:Name="textblock2"
TextWrapping="Wrap"
/>
</StackPanel>
</Page>
MainPage.xaml.cs
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace UniversalAppTutorials
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private void button1_click(object sender, RoutedEventArgs e)
{
// Set the text block text
textblock2.Text = "Your favorite colors are : ";
// Initialize an empty string
string colors = string.Empty;
// Initiaze an array of checkboxes
CheckBox[] checkboxes = new CheckBox[] {
checkbox_1,
checkbox_2,
checkbox_3,
checkbox_4,
checkbox_5,
checkbox_6,
checkbox_7
};
foreach (CheckBox c in checkboxes) {
if (c.IsChecked == true) {
if (colors.Length > 1) {
colors += ", ";
}
// Add the checked color to the selected colors list
colors += c.Content;
}
}
// Finally, display the checked colors to text block
textblock2.Text += colors;
}
}
}




- UWP - Polygon example
- UWP - Rectangle example
- UWP - Get ComboBox selected item
- UWP - ListView multi select example
- UWP - ListView item style example
- UWP - How to change ListView item height
- UWP - ListView alternate item style
- UWP - How to create a ListView programmatically
- UWP - How to use RadioButton
- UWP - ToggleSwitch example
- UWP - Hyperlink text element example
- UWP - Slider example
- UWP - Create Button programmatically
- UWP - RepeatButton example
- UWP - Button click event