I'm writing a small Silverlight media player application. In the top of the page i have an horizontal listbox with listboxitems. The listbox is bound to a datasource containg an object I've created called ContentItem. The ContentItem is defined like this:
public class ContentItem
{
public string CoverUrl { get; set; }
public string ResourceUrl { get; set; }
public ContentItem()
{
}
}
I also have an Media element:
<MediaElement x:Name="MediaBox" Source="http://localhost/repository/FighterPilot.wmv" Stretch="Fill"/>
So my thaught was, when the user chooses a new ContentItem from the listbox, I want to change the source of the MediaElement and start playing the new ContentItem. To do this, I've used the ListBox SelectionChange event: private void CoverFlowList_SelectionChanged(object sender,
System.Windows.Controls.SelectionChangedEventArgs e)
{
MediaBox.Stop();
ListBoxItem SelectedItem = (ListBoxItem)sender;
ContentItem SelectedContent = (ContentItem)SelectedItem.Content;
MediaBox.Source = new Uri(SelectedContent.ResourceUrl);
MediaBox.Play();
}
But this does not want to work. When I debug the code, I can step all the way to ListBoxItem SelectedItem = (ListBoxItem)sender;
but at this line it all freezes. The webbrowser shows a blank page, and the debugger (Visual Studio 2008) seems is still debugging but nothing happens.
Any idea what I'm doing wrong here? Any tips on how I could implement this functionality different?
I'm very thankful for advice!