MediaElement.SetSource Method (MediaStreamSource)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

This sets the source of a MediaElement to a subclass of MediaStreamSource.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)


Public Sub SetSource ( _
    mediaStreamSource As MediaStreamSource _
public void SetSource(
    MediaStreamSource mediaStreamSource



Exception Condition

The mediaStreamSource is null.


The specified mediaStreamSource is invalid, or does not exist.


After calling this method, MediaElement.Source returns null. If this is called and MediaElement.Source is set, the last operation wins.

If a MediaElement is removed from the UI tree while is has an opened MediaStreamSource, subsequent calls to SetSource may be ignored. To ensure featureSetSource calls will work, set the Source property to nulla null reference (Nothing in Visual Basic) before detaching the MediaElement from the UI tree,.

Version Information


Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0


For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.