Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Video Brush in WPF

0.00/5 (No votes)
28 Jun 2013 2  
This tip explains how to use video brush and visual property as a media element.

Introduction

A VisualBrush is used to fill UI elements. The following code uses a VisualBrush to fill a rectangle. We can define a simple or complex UI element and assign it to the VisualBrush.Visual property using VisualBrush. We can then use the VisualBrush to create interesting effects, such as reflection and magnification.  

How to Use

This example shows how to use the VisualBrush class with a Visual. Here, I am using media element as visual. A Visual object usually hosts one container panel such as a Grid or StackPanel and on this container.

Here is the XAML code:

<Window x:Class="WpfApplication4.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>

        <Ellipse Height="100" Width="100" Name="elipsemedia" >
            <Ellipse.Fill>
                <VisualBrush TileMode="None">
                    <VisualBrush.Visual>
                        <MediaElement Source=
			"D:\TestingDB\wpftheme\wpftheme\Image\Wildlife.wmv" />
                    </VisualBrush.Visual>
                </VisualBrush>
            </Ellipse.Fill>
        </Ellipse>
    </Grid>

</Window>
Colourised in 20ms

Here, I used Ellipse.fill property for video brush. This fill property  sets the Brush that specifies how the shape's interior is painted.

History

  • 27th June, 2013: Initial post

This tip is based on http://articlesforprogramming.blogspot.in/2013/06/visual-brush-in-wpf.html.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here