I'm binding values to a combobox
from a List. It lists numbers from one to five. Now I want to show the selected number in its numeric format. Means when a user selects "Four" from combobox
, then the selected item of combobox
should show as it's numeric form "4". Is it possible in UWP?
List<Item> available_Nums = new List<Item>();
available_Nums.Add(new Item { Number = 1, Text = "One" });
available_Nums.Add(new Item { Number = 2, Text = "Two" });
available_Nums.Add(new Item { Number = 3, Text = "Three" });
available_Nums.Add(new Item { Number = 4, Text = "Four" });
available_Nums.Add(new Item { Number = 5, Text = "Five" });
ComboBox2.ItemsSource = available_Nums;
private void ComboBox2_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ComboBox2.SelectedItem = (ComboBox2.SelectedItem as Item).Number;
}
<ComboBox x:Name="ComboBox2" SelectionChanged="ComboBox2_SelectionChanged" Grid.Row="0" Grid.ColumnSpan="2" HorizontalAlignment="Left">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock x:Name="comboTextBox" Text="{Binding Text}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>