每当从选择器访问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());
}
}
答案 0 :(得分:0)
很可能是因为您的ListPicker.SelectedItem
是null
。在尝试对其执行任何操作之前先检查一下。无论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());
}
}
}