現在選択されているアイテムのコンテンツを取得して表示する方法が見つかりません。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);
}
}
「string text ...」行でこの例外が発生します。
オブジェクト参照がオブジェクト インスタンスに設定されていません