SIGN UP MEMBER LOGIN:    
ARTICLE

Video Brush in WPF

Posted by Mahesh Chand Articles | WPF with C# 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
share 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
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Become a Sponsor