我有wp8应用程序,列表选择器绑定到xml数据源,当我选择项目我希望能够获得“源”src位置文件位置我有这个功能当我检查项目我发现src选择了名称
private void SoudListPicker_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
// TODO: Add event handler implementation here.
var item = (sender as ListPicker).SelectedItem;
MessageBox.Show("Selected Item is : " + item);
}
答案 0 :(得分:3)
var
使用赋值语句右侧的结果类型来推断它的类型,在这种情况下(我相信)是object
。
要使属性可见,您需要将SelectedItem
强制转换为实际类型。
private void SoudListPicker_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
// TODO: Add event handler implementation here.
var item = ((sender as ListPicker).SelectedItem) as Expression.Blend.SampleData.soundsEFXSampleDataSource3.sound;
if(item != null)
MessageBox.Show("Selected Item is : " + item.src);
}