Reputation: 72191
so I'm trying to change the value IsSelected on ComboBox item in code:
if (roamingSettings.Values.ContainsKey("tempValue"))
{
switch (roamingSettings.Values["tempValue"].ToString())
{
case "Celsius":
Celsius.IsSelected = true;
break;
case "Kelvin":
Kelvin.IsSelected = true;
break;
case "Fahrenheit":
Fahrenheit.IsSelected = true;
break;
}
}
This code gets triggered on page restore, logic works fine, the value gets passed onto "OnNavigatedTo(NavigationEventArgs e)" method (I've borrowed this method from Microsoft UWP Examples) and I can see that e.Content has the correct value. But the item doesn't get selected. Any ideas? Thanks in advance!
ps. Complete code on https://github.com/4c74356b41/UWP-04 (this happens on settings.xaml and settings.xaml.cs)
Upvotes: 0
Views: 75
Reputation: 433
What if you don't force an item to be seleted, but force the combobox to select an item ?
Something like
switch (roamingSettings.Values["tempValue"].ToString())
{
case "Celsius":
ComboBox.selectedItem = Celsius;
break;
case "Kelvin":
ComboBox.selectedItem = Kelvin;
break;
case "Fahrenheit":
ComboBox.selectedItem = Fahrenheit;
break;
}
Upvotes: 3