listpicker Wp8中的系统访问冲突错误

时间:2014-11-13 09:35:14

标签: windows-phone-8

每当从选择器访问seleceted项时,我在listpicker的选择Changed事件中收到错误 代码:

private void AppNamePicker_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    ListPicker picker = sender as ListPicker;

    if (picker.SelectedItem.ToString()!="---Select---")
    {
           MessageBox.Show(picker.SelectedItem.ToString());
     }

}

1 个答案:

答案 0 :(得分:0)

很可能是因为您的ListPicker.SelectedItemnull。在尝试对其执行任何操作之前先检查一下。无论SelectionChanged上的ListPicker中是否有任何项目,Loaded都会触发。

private void AppNamePicker_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    ListPicker picker = sender as ListPicker;
    if (picker.SelectedItem != null)
    {
        if (picker.SelectedItem.ToString() != "---Select---")
        {
            MessageBox.Show(picker.SelectedItem.ToString());
        }
    }
}