ich offensichtlich nicht begreifen SelectedValue zu ändern verwenden, welches Element ein Kombinationsfeld in UWP zeigtUWP ComboBox SelectedValue nicht gesetzt ist
Die XAML einfach
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<ComboBox x:Name="comboBoxColor" />
</Grid>
Der Code-behind ist nicht Diese sehr tief
public MainPage()
{
this.InitializeComponent();
}
public void page_Loaded(object sender, RoutedEventArgs e)
{
populateDdlMultiColor();
comboBoxColor.SelectedValue = Colors.Red;
//comboBoxColor.SelectedIndex = 0 works tho
}
private void populateDdlMultiColor()
{
comboBoxColor.ItemsSource = ColorDict();
comboBoxColor.DisplayMemberPath = "Key";
comboBoxColor.SelectedValuePath = "Value";
}
private Dictionary<string,Color> ColorDict()
{
Dictionary<string, Color> L = new Dictionary<string, Color>();
L.Add("reddish",Colors.Red);
return L;
}
ist offensichtlich bastel-Spielzeug, aber es nicht die gleiche Art und Weise mein Code nicht: Nach dem SelectedValue Einstellung, die Combo-Box ist auf Index -1 und SelectedValue ist null. Wenn ich SelectedIndex auf einen korrekten Wert setze [siehe Kommentar], funktioniert das Kombinationsfeld - es wurde geladen.