【发布时间】:2014-07-16 03:15:52
【问题描述】:
我找不到获取和显示当前所选项目内容的方法,这里是 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);
}
}
它在“字符串文本...”行给了我这个例外:
对象引用未设置为对象的实例
【问题讨论】:
-
您在哪一行得到异常?你可能需要拿走你的 catch 块才能看到这个。
-
它给了我“字符串文本...”行的异常。其余的工作正常,它给了我当前的索引。
-
我认为这个链接可能会回答你的问题。 stackoverflow.com/questions/15325243/…
标签: c# windows-phone-8 listpicker