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
x:Name="stack_panel1"
Orientation="Horizontal"
Background="LightYellow"
Padding="100"
>
<ComboBox
x:Name="ComboBox1"
Header="Select A Color"
DisplayMemberPath="ColorName"
SelectedValuePath="ColorValue"
SelectionChanged="ComboBox1_SelectionChanged"
>
</ComboBox>
<TextBlock
x:Name="TextBlock1"
FontFamily="Consolas"
FontSize="25"
Foreground="DarkGreen"
Margin="50,5,5,5"
/>
</StackPanel>
</Page>
MainPage.xaml.cs
using Windows.UI.Xaml.Controls;
using System.Collections.Generic;
namespace UniversalAppTutorials
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
// Initialize a new list of colors
List<color> colors = new List<color>();
// Put some items to the collection
colors.Add(new color("INDIANRED", "#CD5C5C"));
colors.Add(new color("SALMON", "#FA8072"));
colors.Add(new color("CRIMSON", "#DC143C"));
colors.Add(new color("DEEPPINK", "#FF1493"));
colors.Add(new color("CORAL", "#FF7F50"));
colors.Add(new color("ORANGE", "#FFA500"));
colors.Add(new color("YELLOW", "#FFFF00"));
colors.Add(new color("PEACHPUFF", "#FFDAB9"));
// Specify the ComboBox items source
ComboBox1.ItemsSource = colors;
// Define the both properties programmatically
//ComboBox1.DisplayMemberPath = "ColorName";
//ComboBox1.SelectedValuePath = "ColorValue";
}
public class color{
public string ColorName { get; set; }
public string ColorValue { get; set; }
public color(string colorName,string colorValue) {
this.ColorName = colorName;
this.ColorValue = colorValue;
}
}
private void ComboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// Get the ComboBox instance
ComboBox comboBox = sender as ComboBox;
// Get the ComboBox selected item value and display on TextBlock
TextBlock1.Text = "You selected:\n";
TextBlock1.Text += "Value : " + comboBox.SelectedValue.ToString();
}
}
}



- UWP - CalendarDatePicker example
- UWP - TimePicker example
- UWP - ComboBox default selected item
- UWP - ComboBox item style example
- UWP - Get ComboBox selected value
- UWP - ComboBox ItemsSource example
- UWP - TextBox ScrollBar example
- UWP - How to change TextBox style
- UWP - Select TextBox all text when get focus
- UWP - How to launch app in full screen mode
- UWP - How to set app launch window size
- UWP - How to set app window minimum size
- UWP - How to bold text in a TextBlock
- UWP - How to underline text in a TextBlock
- UWP - How to change TextBlock background color