SetHandler Method
Description
Enables event handling for a XAML object which links XAML events with a Subroutine or Function in code.
Syntax
Public Sub SetHandler( _
ByVal [Handler](#) As Object _
)
Parameters
- Handler: Reference to the parent object.
Remarks
SetHandler enables event handling for a XAML object. This will link XAML events with a Subroutine or Function in code (VB, C#, etc.).
Any XML Markup that is in the control's Caption property will be translated to viewable text. To enable event handling for an XML object, call SetHandler. With SetHandler, you only need to specify the Handler of the control, and all function names will be calculated from Markup.
In the sample below, the "HyperClick" and "Hyperlink_MouseRightButtonUpEvent" subroutines are used to handle the Click and MouseRightButtonUp events of the hyperlink in the XML.
Connecting XML events to your code can be very useful if you need to react to the events of elements of markup.
Example
Catching the Click and RightMouseUp event in Markup for a Hyperlink (Visual Basic) shows how to catch the Click and RightMouseUp event in Markup for a Hyperlink. In this case, the text is in the Caption of a BackStageButton control.
Public Sub HyperClick(ByVal Sender As MarkupObject, ByVal Args As MarkupRoutedEventArgs)
Dim tempHL As MarkupHyperlink
Set tempHL = Sender
MsgBox tempHL.Tag + " was clicked"
End Sub
Public Sub Hyperlink_MouseRightButtonUpEvent(ByVal Sender As MarkupObject, ByVal Args As MarkupRoutedEventArgs)
Dim tempHL As MarkupHyperlink
Set tempHL = Sender
MsgBox tempHL.Tag + " has been right clicked"
End Sub
BackstageButton2.MarkupContext.SetHandler Me
BackstageButton2.Caption = "Text with Hyperlink"
See Also
Copyright (c) 1998-2024 Codejock Technologies. All rights reserved.