我在我的xaml代碼中有一個ListPicker,它包含的不止是ListPickerItem,我想根據選擇的ListPickerItem在我的地圖上顯示一個圖釘。如何在windows phone 8中基於ListPickerItem選擇做功能
這是我的XAML:
<toolkit:ListPicker Foreground="white" Opacity="0.9" x:Name="OptionSelection" Margin="0,18,0,0" SelectionChanged="Picker">
<toolkit:ListPickerItem Tag="1" x:Name="Option1" Content="Item1"/>
<toolkit:ListPickerItem Tag="2" x:Name="Option2" Content="Item2"/>
<toolkit:ListPickerItem Tag="3" x:Name="Option3" Content="Item3"/>
</toolkit:ListPicker>
這裏是SelectionChanged事件我的CS代碼:
private void Picker(object sender, SelectionChangedEventArgs e)
{
var tag = ((ListPickerItem)OptionSelection.SelectedItem).Tag;
if (tag.Equals(1))
{
MessageBox.Show("Item1 selected"); //I will replace this with my geolocation function later.
}
}
主要是我想知道的if語句如何應用在我的代碼,這將有助於我根據選定的項目添加地理定位功能。
什麼問題嗎? – Sajeetharan
它給出了一個例外,這裏詳細說明 DataBoundApp3.DLL中發生了類型'System.NullReferenceException'的異常,但未在用戶代碼中處理 附加信息:未將對象引用設置爲對象的實例。 – user3269487