Reputation: 33
I use some ListPicker
to manage my apps settings.
As I can see in when using a breakpoint in OnNavigatedTo()
, the SelectedIndex
is always set to the correct value, but when the dialog is shown, all ListPicker
show the first item.
When I popup a LictPicker
, then the correct item is highlighted and also saved correctly when the dialog is closed.
The Definition in XAML:
<toolkit:ListPicker x:Name="ListPickHybrid" Margin="0,0, 0, 0"
SelectedIndex="{Binding HybridSetting, Mode=TwoWay, Source={StaticResource appSettings}}" BorderBrush="White" >
<toolkit:ListPickerItem Content="Nur Online" />
<toolkit:ListPickerItem Content="Immer offline" />
<toolkit:ListPickerItem Content="Automatisch" />
</toolkit:ListPicker>
And here is the code:
public int HybridSetting {
get {
int val = GetValueOrDefault<int>(BIS_Common.SETTINGS_HYBRIDMODUS, (int)HybridModus.Hybrid_Undefined);
return val;
}
set {
if (AddOrUpdateValue(BIS_Common.SETTINGS_HYBRIDMODUS, value)) {
HybridModus status = (HybridModus) value;
if (status != HybridModus.Hybrid_Undefined)
BIS_Common.settingHybridStatus = status;
Save();
}
}
}
But when I make some nonsens as:
try { ListPickHybrid.SelectedIndex = 99; }
catch (Exception) { }
In the OnNavigatedTo()
the exception is thrown and then the ListPicker
shows the correct Item !!
It makes no sense to me, that changing the SelectedIndex
to an not existing value, brings me to the achieved goal.
What else can I do, to make ListPicker
shows the selected item after starting up?
Upvotes: 0
Views: 166
Reputation: 1084
I'm facing the same Issue right now... Just in case anybody runs needs it, I have found another crude workaround:
Before the ItemSource is populated:
this.YourPicker.Visibility = System.Windows.Visibility.Collapsed;
After the ItemSource is populated:
this.YourPicker.Visibility = System.Windows.Visibility.Visible;
Upvotes: 2
Reputation: 1
This is a crude workaruond but try using the "open()" method on the listpicker after it has been populated with items and the "SelectedItemIndex" has been set.
ListPickHybrid.open();
Upvotes: 0