ARTICLE

Video Brush in WPF

Posted by Mahesh Chand Articles | WPF February 20, 2010
This article demonstrates how to implement video brushes in WPF using MediaElement XAML element.
Reader Level:

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.

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

Listing 27

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

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

Listing 28

Login to add your contents and source code to this article
post comment
     

at end of listing 28 I assign listbox background to videobrush but do not see the video, can it work?

Posted by John Brosowsky Sep 03, 2010
COMMENT USING
PREMIUM SPONSORS
Over-C is a holistic consortium of communications and technology specialists. We build, deploy and market both business as well as consumer products and solutions.
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Get Career Advice from Experts