user474901
user474901

Reputation:

get value from var item?

I have wp8 app that has list picker bind to xml data sourse and when I select item I want to be able to get "source" src location file location I have this function when I inspect the item i found src selected with name enter image description here

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);
}

Upvotes: 0

Views: 65

Answers (1)

xenolightning
xenolightning

Reputation: 4230

var uses the resultant type on the right-hand side of the assignment statement to infer it's type, which (I believe) is object is this case.

To make the properties visible you need to cast the SelectedItem to it's actual type.

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);
}

Upvotes: 3

Related Questions