Tuesday, September 7, 2010

Adding a VideoBrush in Silverlight

Using a VideoBrush in Silverlight Application


VideoBrush elements are very similar to the ImageBrush. Instead of an image, they define a video MediaElement that is applied as a brush. You can apply them to the properties of Silverlight controls the same way that the ImageBrush is applied.

To apply a VideoBrush to a Silverlight control, you need to define the VideoBrush element just as you do with an ImageBrush. However, different from an ImageBrush, you need to set a SourceName property that points to the x:Name of the MediaElement. Therefore, you also need to define a MediaElement separate from the Silverlight control. If you do not want the video to be displayed outside of the Silverlight control, set the Opacity property of the MediaElement to 0.

Eg:

< MediaElement Source="first.wmv"
x:Name="movie"
Opacity="0"/ >


< TextBox Height="100" Width="150" >
< TextBox.Background >
< VideoBrush SourceName="movie" Stretch="UniformToFill"/ >
< /TextBox.Background >
< /TextBox >

No comments: