Group Discounts available for 3+ students and Corporate Clients

Media Elements in SilverLight

Media element

This control is used to access default video player from the operating system, using this control we can play different type of video formats and audio formats, while working with video brush we have to decide playing source in the media element control, we have to refer media element control reference in the video brush.

Example:- open new silver light Application

Go to XAML code

In the grid tag

<grid X:name = “Layout Root” Background = “white”>

<Media element X: Name = “M1” source = “d:/advit.wmv” opacity = “0”>

</Media Element>

<path X:name = “p1” Height = “300” width = “300” stroke = “Red” stroke thickness = “10”>


<Rectangle Geometry Rect = “10, 10, 200, 200”>

<I rectangle Geometry>

</path. Data>


<video brush source name = “m1”> </video brush>

</path. Fill>





The path control is used to create work space for defining collection of geometries, path.Data tag using for defining one geometry.

Rectangle geometry tag used to define rectangle geometry. Rect property used to decide rectangle geometry size, this property takes four parameters

  1. Starting x location
  2. Starting Y location
  3. Ending X location
  4. Ending Y location


Implementing dynamic control with radial gradient brush

Open new silverlight  application

Add button control on the grid layout

Go to button click event

Private void button  click (object sender, routed E.Vent Args e)


Rectangle r = new rectangle ();

r.Hieght = 200;

r.width = 200;

Radial gradient brush b = new radial gradient brush ();

Gradient stop  g1 = new gradient stop();

G1. Offset = .2;

G1.color = cdors. Red;

  1. gradient stops. Add(g1);

gradient stop g2 = new gradient stop();

g2. Offset = .4;

g2. Color = colors. Green;

  1. gradient stops . add (g2);

gradient stop g3 = new gradient stop();

g3. Color = colors. Blue;

b.gradient stops . add (g3);

r.fill = b;

Layout Root. Children. Add (r);

  • Layout root is default name to the grid container
  • Layout root. Children statement refers all controls from the grid container
  • ‘add’ method adding new control on the container


“At TekSlate, we are trying to create high quality tutorials and articles, if you think any information is incorrect or want to add anything to the article, please feel free to get in touch with us at, we will update the article in 24 hours.”

0 Responses on Media Elements in SilverLight"

Leave a Message

Your email address will not be published. Required fields are marked *


Please Enter Your Details and Query.
Three + 6