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="Azure"
Padding="125"
>
<ComboBox
x:Name="ComboBox1"
Header="Select A Color"
Foreground="Crimson"
FontSize="22"
FontFamily="MV Boli"
>
</ComboBox>
</StackPanel>
</Page>
MainPage.xaml.cs
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Text;
namespace UniversalAppTutorials
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
// Initialize a new string array
string[] colors = {
"AntiqueWhite",
"Green",
"Orange",
"DarkOliveGreen",
"Cornsilk",
"Cyan",
"BlanchedAlmond",
"Beige",
"CornflowerBlue"
};
// Get the ComboBox item collection
ItemCollection ic = ComboBox1.Items;
// Loop through the array items
for (int index = 0; index < colors.Length; index++)
{
// Initialize a new ComboBoxItem instance
ComboBoxItem item = new ComboBoxItem();
// Add the content to item
item.Content = colors[index];
// Set the item border as item separator
item.BorderThickness = new Thickness(0, 0, 0, 2);
item.BorderBrush = new SolidColorBrush(Colors.DarkBlue);
// Item text style
item.FontSize = 22;
item.FontWeight = FontWeights.Medium;
item.FontStretch = FontStretch.ExtraExpanded;
item.FontFamily = new FontFamily("MV Boli");
item.Padding = new Thickness(15, 10, 50, 10);
item.Foreground = new SolidColorBrush(Colors.Navy);
// Set the item width
item.Width = 300;
if (index % 2 == 0)
{
// Set the regular item background
item.Background = new SolidColorBrush(Colors.CornflowerBlue);
}
else
{
// Set the alternate item background
item.Background = new SolidColorBrush(Colors.SkyBlue);
}
// Finally, add the item to the ComboBox item collection
ic.Add(item);
}
}
}
}