我找不到获取和显示当前所选项目内容的方法,这里是 XAML:
<toolkit:ListPicker Name="lp" Header="Network" SelectionChanged="selectionChanged">
<toolkit:ListPickerItem Content="aaa" />
<toolkit:ListPickerItem Content="bbb" />
</toolkit:ListPicker>
和其余的代码:
private void selectionChanged(object sender, SelectionChangedEventArgs e)
{
try
{
if (e.RemovedItems != null && e.RemovedItems.Count > 0)
{
if (this.lp.SelectedItem != null)
{
var selectedItem = (sender as ListPicker).SelectedItem;
int selindex = lp.SelectedIndex; //just for testing
MessageBox.Show(selindex.ToString()); //just for testing
string text = (lp.SelectedItem as ListBoxItem).Content.ToString();
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
它在“字符串文本...”行给了我这个例外:
你调用的对象是空的