VideoDrawing Class

Plays a media file. If the media is a video file, the VideoDrawing draws it to the specified rectangle.

Namespace: System.Windows.Media
Assembly: PresentationCore (in presentationcore.dll)
XML Namespace:

public sealed class VideoDrawing : Drawing
public final class VideoDrawing extends Drawing
public final class VideoDrawing extends Drawing
 You cannot use this managed class in XAML. 

Although you can declare an instance of this class in XAML, you cannot load and play its media without using code. To play media in XAML only, use a MediaElement.

Despite its name, a VideoDrawing can be used to play audio.

Performance Note: A VideoDrawing provides fewer features then an MediaElement: VideoDrawing does not support layout, input, or focus. However, because it does not support these features, VideoDrawing provides performance benefits making them ideal for describing backgrounds, clip art, and for low-level drawing with Visual objects. See Drawing Objects Overview for more information.

An VideoDrawing is a type of Freezable object and therefore can be frozen to improve performance. For information about Freezable features, such as freezing and cloning, see the Freezable Objects Overview.

To play an audio or video file, you use a VideoDrawing and a MediaPlayer. There are two ways to load and play media. The first is to use a MediaPlayer and a VideoDrawing by themselves, and the second way is to create your own MediaTimeline to use with the MediaPlayer and VideoDrawing.


When distributing media with your application, you cannot use a media file as a project resource, like you would an image. In your project file, you must instead set the media type to Content and set CopyToOutputDirectory to PreserveNewest or Always.

The following example uses a VideoDrawing and a MediaPlayer to play a video file once.

// Create a VideoDrawing.
MediaPlayer player = new MediaPlayer();

player.Open(new Uri(@"sampleMedia\xbox.wmv", UriKind.Relative));

VideoDrawing aVideoDrawing = new VideoDrawing();

aVideoDrawing.Rect = new Rect(0, 0, 100, 100);

aVideoDrawing.Player = player;

// Play the video once.

To gain additional timing control over the media, use a MediaTimeline with the MediaPlayer and VideoDrawing objects. The MediaTimeline enables you to specify whether the video should repeat.

The following example uses a MediaTimeline with the MediaPlayer and VideoDrawing objects to play a video repeatedly.

// Create a VideoDrawing that repeats.

// Create a MediaTimeline.
MediaTimeline mTimeline = 
    new MediaTimeline(new Uri(@"sampleMedia\xbox.wmv", UriKind.Relative)); 

// Set the timeline to repeat.
mTimeline.RepeatBehavior = RepeatBehavior.Forever;

// Create a clock from the MediaTimeline.
MediaClock mClock = mTimeline.CreateClock();

MediaPlayer repeatingVideoDrawingPlayer = new MediaPlayer();
repeatingVideoDrawingPlayer.Clock = mClock;

VideoDrawing repeatingVideoDrawing = new VideoDrawing();
repeatingVideoDrawing.Rect = new Rect(150, 0, 100, 100);
repeatingVideoDrawing.Player = repeatingVideoDrawingPlayer;  

Note that, when you use a MediaTimeline, you use the interactive ClockController returned from the Controller property of the MediaClock to control media playback instead of the interactive methods of MediaPlayer.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0