Click here to Skip to main content
15,881,172 members
Articles / Desktop Programming / WPF
Tip/Trick

Video Brush in WPF

Rate me:
Please Sign up or sign in to vote.
3.20/5 (3 votes)
27 Jun 2013CPOL 19.4K   7   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:

C++
<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>

Image 1

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 1 Pin
webmaster44228-Jun-13 6:14
webmaster44228-Jun-13 6:14 
Questionreference Pin
josh-jw27-Jun-13 20:05
josh-jw27-Jun-13 20:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.