PlaylistItem MediaSource DataBinding

Oct 11, 2010 at 12:23 PM
I am trying to replace the basic sample with databinding in MVVM scenario:

      <Media:PlaylistItem MediaSource="{Binding ViewModelUri}"/>

My View constructor takes ViewModel as a parameter and sets the DataContext of a View to my ViewModel. 
When View constructor calls InitializeComponent() (standard view initialization method), I get following error:
"Object of type 'System.Windows.Data.Binding' cannot be converted to type 'System.Uri'"
ViewModelUri is a property of a ViewModel (type System.Uri).

DataBinding works with other controls being used in the View, but fails for the SMFPlayer.
Any suggestion?

Oct 23, 2010 at 12:20 AM

I am having an identical issue when attempting to bind to a property located in the View's DataContext( i.e. ViewModel). In fact I get this error when I try to bind to any property. "Object of type 'System.Windows.Data.Binding' cannot be converted to type [insert type here]."

Can someone please speak to this as its very frustrating.


May 5, 2011 at 10:53 AM
Edited May 5, 2011 at 10:54 AM


Same problem in my project.

Databinding to my viewmodel properties works ok for other controls.

I get the error "Object of type 'System.Windows.Data.Binding' cannot be converted to type 'System.Uri'" as described by the other users for the SMF player.

Other alternative is to add playlistitem via code, but it doesnt seem to work either. Fiddler shows no activity, so the manifest is not even request.

            PlaylistItem item = new PlaylistItem();
            item.DeliveryMethod = Microsoft.SilverlightMediaFramework.Plugins.Primitives.DeliveryMethods.AdaptiveStreaming;
            item.MediaSource = myStreamUri;
May 5, 2011 at 4:13 PM

To convert a string to a Uri during binding you need to use a converter. Here's a blog post on how to do this:

(the second example in the blog post shows how to do this)

LuisFaustino, to play a smooth streaming file you will need to make sure:

1) You have a clientaccesspolicy.xml file (or crossdomain.xml) in the root of your domain

2) You've added a reference to Microsoft.SilverlightMediaFramework.Plugins.Smoothstreaming to your project

3) You've added a reference to Microsoft.Web.Media.Smoothstreaming to your project (comes with the IIS client setup -- there is a link to this on the download page here on codeplex).


May 5, 2011 at 5:39 PM
Edited May 5, 2011 at 5:40 PM

Tim, thanks for your reply.

I didnt try the converter because my property was of type Uri, so I didnt think the Converter would make a difference. I will try it and see how it goes.


In the meanwhile I managed to make it work using XamlReader.Load into a StackPanel.

StringBuilder sb = new StringBuilder();

sb.Append("<Core:SMFPlayer xmlns:Core=\"clr-namespace:Microsoft.SilverlightMediaFramework.Core;assembly=Microsoft.SilverlightMediaFramework.Core\" xmlns=\"\" AutoPlay=\"True\">");


sb.Append("<Media:PlaylistItem xmlns:Media=\"clr-namespace:Microsoft.SilverlightMediaFramework.Core.Media;assembly=Microsoft.SilverlightMediaFramework.Core\" DeliveryMethod=\"AdaptiveStreaming\" MediaSource=\"" + MyMediaSourceString + "\"/>");



SMFPlayer player = (SMFPlayer) XamlReader.Load(sb.ToString());


May 5, 2011 at 7:20 PM

Luis, my mistake... I should have tested before I replied.

You cannot bind to the PlaylistItem object because it does not inherit DependencyObject. This is by design because you cannot create a DependencyObject from a background thread (which may be important to some users programmatically creating their playlists). You could however bind to the Playlist property on SMFPlayer and have your view model construct the observablecollection of PlaylistItems.

Hopefully that helps explain things,


Jul 2, 2012 at 3:48 AM

This is quite unfortunate, I wanted to have a textbox that I bind to the playlist's single entry's MediaSource property.

Now obviously one has to use code-behind instead.