Partager via


VideoBrush

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Paints an area with video content.

<VideoBrush   .../>

Managed Equivalent

VideoBrush

Remarks

A VideoBrush is a type of Brush object similar to a LinearGradientBrush or an ImageBrush. However, instead of painting an area with a solid color, a gradient, or an image, a VideoBrush paints an area with video content, which is provided by a MediaElement object. Just like the other brush types, you can use a VideoBrush to paint the Fill of a shape such as a Rectangle or the geometry contents of a Path, the Background of a Canvas, or the Foreground of a TextBlock or Run.

To use a VideoBrush, you create a MediaElement, apply the VideoBrush to the object that you want to paint, and set the VideoBrush object's SourceName property to the Name value of the MediaElement that you created.

Example

The following example uses a VideoBrush object to paint the Foreground of a TextBlock.

<Canvas
  xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml">
  
    <MediaElement 
      x:Name="butterflyMediaElement" 
      Source="sampleMedia/Butterfly.wmv" IsMuted="True"
      Opacity="0.0" IsHitTestVisible="False" />
      
    <TextBlock Canvas.Left="5" Canvas.Top="30"  
      FontFamily="Verdana" FontSize="120" 
      FontWeight="Bold" TextWrapping="Wrap"
      Text="Video">
      
        <!-- Paint the text with video. -->
        <TextBlock.Foreground>
          <VideoBrush SourceName="butterflyMediaElement" Stretch="UniformToFill" />
        </TextBlock.Foreground>
    </TextBlock>
    
</Canvas>