[英]c# ComboBox isSelected doesn't work as expected
所以我想更改代碼中ComboBox項目上的IsSelected值:
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;
}
}
該代碼在頁面還原時被觸發,邏輯工作正常,該值被傳遞到“ OnNavigatedTo(NavigationEventArgs e)”方法(我從Microsoft UWP示例中借用了此方法),並且可以看到e.Content具有正確的值。 但是沒有選擇該項目。 有任何想法嗎? 提前致謝!
PS。 在https://github.com/4c74356b41/UWP-04上的完整代碼(這發生在settings.xaml和settings.xaml.cs上)
如果您不強制選擇一項,而是強制組合框選擇一項怎么辦?
就像是
switch (roamingSettings.Values["tempValue"].ToString())
{
case "Celsius":
ComboBox.selectedItem = Celsius;
break;
case "Kelvin":
ComboBox.selectedItem = Kelvin;
break;
case "Fahrenheit":
ComboBox.selectedItem = Fahrenheit;
break;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.