Getting object from SelectionChangedEventArgs e Windows Phone 8

PutraKg picture PutraKg · Mar 27, 2013 · Viewed 8k times · Source

I am using Telerik Slide View control and it supports a SelectionChanged event

private void radSlideView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{        
    var addedItems = e.AddedItems;
}

e contains the MainViewModel object which contains the FileName property. How do I "extract" the FileName property from e? addedItems is aSystem.Collection.IList type

enter image description here

Answer

Mike Dinescu picture Mike Dinescu · Mar 27, 2013

You need to cast:

if(e.AddedItems.Length > 0)       // make sure there is at least one item..
{
   MainViewModel firstItem = e.AddedItems[0] as MainViewModel;    // cast..
   if(firstItem != null)                                          // if not null..
   {
       string fileName = firstItem.FileName;                      // get the file name
   }
}