WPF Video Brush in VB.NET
This article demonstrates how to implement video brushes in WPF using MediaElement XAML element.
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.
Dim McMediaElement As New MediaElement()
McMediaElement.Source = New Uri("Lake.wmv", UriKind.Relative)
McMediaElement.IsMuted = False
Dim videoBrush As New VisualBrush()
videoBrush.Visual = McMediaElement
Listing 28