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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

The Stop Method<br />

This will stop the current media playback, regardless of whether it is currently playing or<br />

paused. Here’s an example:<br />

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

med.Stop();<br />

H<strong>and</strong>ling Events<br />

In this section, we’ll first look at the common events that are available to all XAML elements<br />

in <strong>Silverlight</strong>, <strong>and</strong> then toward the end of the section, we’ll look into those that<br />

work specifically with the MediaElement.<br />

Managing Focus with the GotFocus <strong>and</strong> LostFocus Events<br />

The only object that can receive Focus events in <strong>Silverlight</strong> 1.0 is the root Canvas. When it<br />

receives focus, the GotFocus event will fire. When it loses it, the LostFocus event will fire.<br />

You can use this to determine when the user has selected the <strong>Silverlight</strong> content within<br />

the browser.<br />

Capturing Keyboard Input with the keyDown <strong>and</strong> keyUp Events<br />

As only the root Canvas can receive focus, only the root canvas will receive these events.<br />

The keyDown event will fire when a key is pressed <strong>and</strong> the <strong>Silverlight</strong> control has focus.<br />

It raises two arguments: sender <strong>and</strong> keyEventArgs. The first parameter will always contain<br />

a reference to the Canvas. The second will contain the necessary metadata to extract the<br />

key information. It exposes the following properties:<br />

keyEventArgs.key: This is an integer that represents the key that was pressed. It is<br />

not operating system–specific. This uses a portable key code that is not operating<br />

system–specific. The full key set is available in the SDK documentation.<br />

keyEventArgs.platformKeyCode: This is an operating system-specific integer that represents<br />

the key that was pressed.<br />

keyEventArgs.shift: This is a Boolean that determines the state of the Shift key when<br />

the key was pressed.<br />

keyEventArgs.ctrl: This is a Boolean that determines the state of the Ctrl key when<br />

the key was pressed.

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

Saved successfully!

Ooh no, something went wrong!