The AddEventListener and RemoveEventListener Methods in VB.NET

Print Denso QR Bar Code in VB.NET The AddEventListener and RemoveEventListener Methods

The AddEventListener and RemoveEventListener Methods
Encoding QR Code In Visual Basic .NET
Using Barcode maker for .NET framework Control to generate, create QR Code JIS X 0510 image in .NET applications.
www.OnBarcode.com
QR Code JIS X 0510 Decoder In VB.NET
Using Barcode reader for Visual Studio .NET Control to read, scan read, scan image in .NET framework applications.
www.OnBarcode.com
One of the nice things about Silverlight is how it separates the design and developer artifacts to allow them to work together more efficiently. You can specify an event handler for an item by using a XAML attribute to define the name of the function that will have the code to run in response to the event. For example, you can use the syntax MouseLeftButton = "handleClick" to declare that you want to use the JavaScript function handleClick when this element is clicked. The drawback with this is that it involves a developer editing the XAML from the designer directly, thus breaking the separation. Silverlight allows you to avoid this by using AddEventListener to declare the handler at runtime. You ll typically do this as part of Silverlight loading. Your handler function will take two parameters: sender, which contains a reference to the control that the event was raised on; and args, which contains any arguments associated with the event. Here s an example:
Barcode Printer In VB.NET
Using Barcode maker for Visual Studio .NET Control to generate, create Barcode image in Visual Studio .NET applications.
www.OnBarcode.com
Generate Matrix Barcode In VB.NET
Using Barcode generation for VS .NET Control to generate, create 2D Barcode image in VS .NET applications.
www.OnBarcode.com
function handleLoad(control, context, sender) { var txtBlock=control.content.findName("txt"); txtBlock.addEventListener("mouseLeftButtonDown", handleTxtClick); } function handleTxtClick(sender,args) { alert("You clicked the Text Block"); }
Code 128C Creation In VB.NET
Using Barcode drawer for .NET Control to generate, create Code 128 image in .NET applications.
www.OnBarcode.com
Linear 1D Barcode Generator In VB.NET
Using Barcode creation for VS .NET Control to generate, create Linear image in .NET framework applications.
www.OnBarcode.com
CHAPTER 16 s PROGRAMMING SILVERLIGHT WITH XAML AND JAVASCRIPT
ANSI/AIM Code 39 Creator In Visual Basic .NET
Using Barcode drawer for .NET framework Control to generate, create Code 39 image in Visual Studio .NET applications.
www.OnBarcode.com
UCC - 12 Drawer In Visual Basic .NET
Using Barcode encoder for Visual Studio .NET Control to generate, create UPCE image in VS .NET applications.
www.OnBarcode.com
You remove the event listener using the RemoveEventListener method on the control. You specify the event name and the handler token in the same way as you did when adding the event listener. Here s an example:
QR Code JIS X 0510 Scanner In Visual Studio .NET
Using Barcode decoder for VS .NET Control to read, scan read, scan image in Visual Studio .NET applications.
www.OnBarcode.com
QR Code Encoder In None
Using Barcode printer for Online Control to generate, create QR Code JIS X 0510 image in Online applications.
www.OnBarcode.com
txtBlock.removeEventListener("mouseLeftButtonDown", handleTxtClick);
UPC Symbol Creation In Visual Studio .NET
Using Barcode encoder for Reporting Service Control to generate, create UPC A image in Reporting Service applications.
www.OnBarcode.com
Making ECC200 In .NET Framework
Using Barcode printer for Visual Studio .NET Control to generate, create Data Matrix 2d barcode image in .NET applications.
www.OnBarcode.com
The CaptureMouse and ReleaseMouseCapture Methods
Barcode Creation In Java
Using Barcode drawer for Android Control to generate, create Barcode image in Android applications.
www.OnBarcode.com
Recognize QR Code 2d Barcode In None
Using Barcode scanner for Software Control to read, scan read, scan image in Software applications.
www.OnBarcode.com
The CaptureMouse method allows the object to receive mouse events even when the mouse isn t within its borders. This is typically used for dragging events, so that once you start dragging an object, you don t have to be within its bounds to continue dragging it. This is released using the ReleaseMouseCapture method. Here s an example where they are being used in conjunction with a handler for the MouseMove event, which will be discussed later in this chapter:
EAN-13 Supplement 5 Maker In .NET
Using Barcode creator for Reporting Service Control to generate, create EAN-13 image in Reporting Service applications.
www.OnBarcode.com
Creating EAN 128 In None
Using Barcode drawer for Font Control to generate, create USS-128 image in Font applications.
www.OnBarcode.com
var isMouseCaptured; function handleLoad(control, context, sender) { var txtBlock=control.content.findName("txt"); txtBlock.addEventListener("MouseLeftButtonDown","mouseDown"); txtBlock.addEventListener("MouseLeftButtonUp","mouseUp"); txtBlock.addEventListener("MouseMove","mouseMove"); isMouseCaptured = false; } function mouseDown(sender,mouseEventArgs) { sender.captureMouse(); isMouseCaptured = true; } function mouseUp(sender, mouseEventArgs) { sender.releaseMouse(); isMouseCaptured = false; } function mouseMove(sender, mouseEventArgs) { if(isMouseCaptured) { sender.setValue("Canvas.Top", mouseEventArgs.getPosition(null).x); sender.setValue("Canvas.Left", mouseEventArgs.getPosition(null).y); } }
UPC-A Supplement 2 Creator In None
Using Barcode generator for Font Control to generate, create UPC-A image in Font applications.
www.OnBarcode.com
Data Matrix ECC200 Decoder In Visual Basic .NET
Using Barcode recognizer for .NET framework Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
CHAPTER 16 s PROGRAMMING SILVERLIGHT WITH XAML AND JAVASCRIPT
Drawing ANSI/AIM Code 128 In None
Using Barcode generation for Software Control to generate, create ANSI/AIM Code 128 image in Software applications.
www.OnBarcode.com
Scan UPC Code In C#.NET
Using Barcode reader for VS .NET Control to read, scan read, scan image in Visual Studio .NET applications.
www.OnBarcode.com
The GetHost Method
This method allows you to get a handle on the Silverlight control, and is useful if you don t want to keep a global reference to it. Here s an example:
function someEvent(sender,args) { var slControl = sender.getHost(); }
The GetParent Method
Similar to GetHost, this returns a reference to the parent element of a particular XAML element. This is particularly useful if you want to walk up the XAML tree. Here s an example:
var txtBlock = control.content.findName("txt"); var txtBlocksParent = txtBlock.getParent();
Using MediaElement Methods
In addition to the common methods, the MediaElement also exposes the methods described in the following subsections.
The Play Method
This will start playback of the current media if it is not currently active or resume playback if it is in a paused state. Here s an example:
var med = sender.content.findName("mplayer"); med.Play();
The Pause Method
This will pause an active playback. Some types of media may not be paused (i.e., streaming media), and in this case the pause command will be ignored. You can check to see if the media can be paused by using the CanPause property. Here s an example:
var med = sender.content.findName("mplayer"); if(med.CanPause) med.Pause(); else // do nothing
CHAPTER 16 s PROGRAMMING SILVERLIGHT WITH XAML AND JAVASCRIPT
The Stop Method
This will stop the current media playback, regardless of whether it is currently playing or paused. Here s an example:
var med = sender.content.findName("mplayer"); med.Stop();
Handling Events
In this section, we ll first look at the common events that are available to all XAML elements in Silverlight, and then toward the end of the section, we ll look into those that work specifically with the MediaElement.
Managing Focus with the GotFocus and LostFocus Events
The only object that can receive Focus events in Silverlight 1.0 is the root Canvas. When it receives focus, the GotFocus event will fire. When it loses it, the LostFocus event will fire. You can use this to determine when the user has selected the Silverlight content within the browser.
Copyright © OnBarcode.com . All rights reserved.