我尝试将项目清除(并将)添加到ListPicker
,但是当应用必须清除所有项目时,所有项目都是错误的 - " SelectedItem必须始终设置为有效值"。我的代码:
<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>
和按钮的动作
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]);
}
}
我尝试了其他选项,但它也行不通。
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]);
}
}
清除您应该使用的选择:
select.SelectedItems.Clear();