Video Brush

A video brush is a brush similar to any other brush. Instead of painting an area with a color, a video brush paints an area with a video. The video contents are provided by a MediaElement. We can use a visualBrush to play a media by setting a MediaElement as its Visual attribute.

The following code snippet creates a MediaElement. The Source property of the MediaElement is the name of the video file.

<MediaElement Source="Lake.wmv" Name="McMediaElement" Width="450" Height="250" LoadedBehavior="Manual" UnloadedBehavior="Stop" Stretch="Fill />

The code snippet in Listing 27 creates a VisualBrush and sets its Visual attribute to a MediaElement.

Code
<VisualBrush >
Code
      <VisualBrush.Visual >
Java
<MediaElement Source="Lake.wmv"                              Name="McMediaElement" Width="450" Height="250" LoadedBehavior="Manual" UnloadedBehavior="Stop" Stretch="Fill />
Code
      </VisualBrush.Visual >
Code
</VisualBrush >

Listing 27

The code snippet in Listing 28 creates a MediaElement and sets it as the Visual property of a VisualBrush.

Code
MediaElement McMediaElement = new MediaElement();
Code
McMediaElement.Source = new Uri("Lake.wmv", UriKind.Relative);
Code
McMediaElement.IsMuted = false;
Code
Code
VisualBrush videoBrush = new VisualBrush ();
Code
videoBrush.Visual = McMediaElement;

Listing 28