08.01.2015 Views

Beginning Web Development, Silverlight, and ASP.NET AJAX

Beginning Web Development, Silverlight, and ASP.NET AJAX

Beginning Web Development, Silverlight, and ASP.NET AJAX

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

398<br />

CHAPTER 16 ■ PROGRAMMING SILVERLIGHT WITH XAML AND JAVASCRIPT<br />

The GetHost Method<br />

This method allows you to get a h<strong>and</strong>le on the <strong>Silverlight</strong> control, <strong>and</strong> is useful if you<br />

don’t want to keep a global reference to it. Here’s an example:<br />

function someEvent(sender,args)<br />

{<br />

var slControl = sender.getHost();<br />

}<br />

The GetParent Method<br />

Similar to GetHost, this returns a reference to the parent element of a particular XAML<br />

element. This is particularly useful if you want to walk up the XAML tree. Here’s an<br />

example:<br />

var txtBlock = control.content.findName("txt");<br />

var txtBlocksParent = txtBlock.getParent();<br />

Using MediaElement Methods<br />

In addition to the common methods, the MediaElement also exposes the methods<br />

described in the following subsections.<br />

The Play Method<br />

This will start playback of the current media if it is not currently active or resume playback<br />

if it is in a paused state. Here’s an example:<br />

var med = sender.content.findName("mplayer");<br />

med.Play();<br />

The Pause Method<br />

This will pause an active playback. Some types of media may not be paused (i.e., streaming<br />

media), <strong>and</strong> in this case the pause comm<strong>and</strong> will be ignored. You can check to see if<br />

the media can be paused by using the CanPause property. Here’s an example:<br />

var med = sender.content.findName("mplayer");<br />

if(med.CanPause)<br />

med.Pause();<br />

else<br />

// do nothing

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!