I try to clear (and add) items to ListPicker, but when the app have to clear all of the items is an error - "SelectedItem must always be set to a valid value". My code:
<toolkit:ListPicker x:Name="select" HorizontalAlignment="Right" Margin="0,135,30,0" VerticalAlignment="Top" Width="195" Height="64" d:LayoutOverrides="HorizontalAlignment" BorderBrush="{x:Null}" FontFamily="Arial" FontWeight="Bold" FontSize="32" Style="{StaticResource ListPickerStyle1}" BorderThickness="0" DataContext="{Binding}">
<toolkit:ListPicker.Background>
<ImageBrush Stretch="Fill" ImageSource="list_picker.png"/>
</toolkit:ListPicker.Background>
and action for a button
private void button_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
select.Items.Clear(); //here is an error
for (int i = 0; i < arrays.Length; i++)
{
select.Items.Add(arrays[i]);
}
}
I try another options, but it doesn't work too.
private void button_Tap(object sender, System.Windows.Input.GestureEventArgs e)
select.SelectedItem = null; // here is an error
select.Items.Clear();
for (int i = 0; i < arrays.Length; i++)
{
select.Items.Add(arrays[i]);
}
}