Skip to content

MarkupContext Object

Description

The MarkupContext object is used to connect XML Markup with methods, functions, and events. This allows XML Markup to call any method, function, or event from code (VB, C#, etc.). It contains methods to create Markup Objects in code.

For a list of all members defined in this module, see MarkupContext Members.

Object Model

MarkupContext Object Model
CreateObject
CreateSolidBrush
CreateThickness
Parse
ToolTipContext

Remarks

MarkupContext is used for two main purposes (works with controls that have a MarkupContext property, i.e., CheckBox, Button, RadioButton, Label, or MarkupLabel):

  1. Connect method calls in XML Markup with actual methods, functions, and events in your code (VB, C#, etc.) when using a CheckBox, Button, RadioButton, Label, or MarkupLabel control.

  2. Contains methods to create Markup Objects in code (Parse, CreateObject, CreateSolidBrush, and CreateThickness), which can only be used with the MarkupLabel control. When using the MarkupLabel control, it allows Markup to be created in code without needing to parse a long markup string. For example, the Markup string "..." can be created in code using Set Grid1 = Context.CreateObject("Grid"). This is accomplished by setting the MarkupLabel.MarkupUIElement property to a Markup object created in code.

Example:

Set MarkupLabel1.MarkupUIElement = StackPanel

Connecting XML events to your code can be very useful when using the MarkupLabel control to create a full-page application using XML. For example, clicking on hyperlinks and buttons, mouse overs, etc.

Any XML Markup that is in the CheckBox, Button, RadioButton, Label, or MarkupLabel control's Caption property will be translated to viewable text. To enable event handling, 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.

Note: SetMethod is now obsolete. Use SetHandler instead.

Example

This example shows how to catch the Click and RightMouseUp events in Markup for a Hyperlink. In this case, the text is in the Caption of a MarkupLabel 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

MarkupLabel2.MarkupContext.SetHandler Me
MarkupLabel2.Caption = "Text with Hyperlink"

See Also


Copyright (c) 1998-2024 Codejock Technologies. All rights reserved.