<ComboBox Canvas.Left="92" Canvas.Top="150"
x:Name="MyComboBox"
Header="My Combo Box"
></ComboBox>
//----- SET UP COMBO BOXES -----
MyComboBox.Items.Clear();
MyComboBox.Items.Add("A");
MyComboBox.Items.Add("B");
MyComboBox.Items.Add("C");
MyComboBox.SelectedIndex = 0;
Styled Example
<ComboBox Canvas.Left="92" Canvas.Top="150" x:Name="MyComboBox" Style="{StaticResource cmbSetupRelays}" />
In App.xaml
<!-- COMBO BOX SETUP RELAYS -->
<Style x:Key="cmbSetupRelays" TargetType="ComboBox">
<Setter Property="Width" Value="178" />
<Setter Property="Height" Value="28" />
<Setter Property="Background" Value="LightGray" />
<Setter Property="Foreground" Value="#460000"/>
<Setter Property="BorderBrush" Value="{ThemeResource SystemControlForegroundTransparentBrush}" />
<Setter Property="BorderThickness" Value="{ThemeResource ButtonBorderThemeThickness}" />
<Setter Property="Padding" Value="0,0,0,0" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="FontFamily" Value="Arial" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="FontSize" Value="13" />
<Setter Property="UseSystemFocusVisuals" Value="True" />
</Style>
Function call
<ComboBox Canvas.Left="92" Canvas.Top="150" x:Name="MyComboBox" SelectionChanged="EditComboBox_SelectionChanged" />
private async void EditComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
try
{
//Get combobox name
var PageObject = sender as ComboBox;
// = PageObject.SelectedIndex;
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("Exception: " + ex.Message);
}
}
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.