This is a mirror of official site: http://jasper-net.blogspot.com/

Implementing Video Brush and Transparent Brush in Windows Presentation Foundation (WPF)

| Monday, August 23, 2010
Implementing Video Brush and Transparent Brush in Windows Presentation Foundation (WPF)

WPF extensively makes use of Media Features. System.Windows.Media is an important namespace in WPF. This namespace provides access to Brush objects and other media features. In this article, I will demonstrate a simple Media Brush feature in WPF. In WPF we have the following Brush Types:

1.    DrawingBrush.
2.    ImageBrush.
3.    LinearGradient Brush.
4.    RadialGradient Brush.
5.    Visual Brush.

From the above brush types, Visual Brush allows to paint color properties of WPF element using any other Visual element. In the article, I have explained the procedure to use this brush.
Creating Video Brush in WPF

Step 1: Open VS2010 and create a WPF Application, name it as ‘WPF_VideoBrush’.
Step 2: In the MainWindow.Xaml, add the Button and a TextBlock element.
Step 3: In this application, since we will be using the Visual Brush using Media Element, add a new Video (*.wmv) file to the project.
Step 4: Open MainWindow.Xaml and create a Visual Brush using the MediaElement:


  1. <
grid>  
  •         <button height="96" horizontalalignment="Left" margin="29,145,0,0" name="button1" verticalalignment="Top" width="462">  
  •             <button.background>  
  •                 <visualbrush>  
  •                     <visualbrush.visual>  
  •                         <mediaelement source="H:\Mahesh_Practice\DotNet40\RTM\WPF_40\WPF_Solutions_DevCurry\WPF_VideoBrush\Lookout.wmv" loadedbehavior="Play"></mediaelement>  
  •                     </visualbrush.visual>  
  •                 </visualbrush>  
  •             </button.background>  
  •         </button>  
  •         <textblock height="110" horizontalalignment="Left" margin="12,12,0,0" name="textBlock1" text
  • Posted via email from .NET Info

    0 comments: