C# ListPicker";SelectedItem必须始终设置为有效值";

C# ListPicker";SelectedItem必须始终设置为有效值";,c#,windows-phone-8,listpicker,C#,Windows Phone 8,Listpicker,我尝试将项目清除(并添加)到列表选择器中,但当应用程序必须清除所有项目时出现错误-“SelectedItem必须始终设置为有效值”。我的代码: <toolkit:ListPicker x:Name="select" HorizontalAlignment="Right" Margin="0,135,30,0" VerticalAlignment="Top" Width="195" Height="64" d:LayoutOverrides="HorizontalAlignment" Bor

我尝试将项目清除(并添加)到
列表选择器中,但当应用程序必须清除所有项目时出现错误-“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按钮\u点击(对象发送者,System.Windows.Input.GestureEventArgs e)
{
select.Items.Clear();//出现错误
for(int i=0;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]);
    }
}
private void按钮\u点击(对象发送者,System.Windows.Input.GestureEventArgs e)
select.SelectedItem=null;//这里有一个错误
select.Items.Clear();
for(int i=0;i
要清除您应该使用的选项:

select.SelectedItems.Clear();

在添加任何项目之前,是否尝试清除它?或者在添加项目之后?在添加项目之后。这是“更改”项目…而不是一个接一个地清除和添加,您可以简单地这样做吗?select.Items=arrayshad不工作。当我这样做时,出现了一些错误-“无法将类型“string[]”隐式转换为“System.Windows.Controls.ItemCollection”和“Property或indexer”System.Windows.Controls.ItemsControl.Items”无法分配给--“它是只读的”有什么想法吗?