Print Page | Close Window

Dynamic XAML

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: MarkupLabel Control
Forum Description: Topics Related to Codejock MarkupLabel Control
URL: http://forum.codejock.com/forum_posts.asp?TID=23166
Printed Date: 28 March 2024 at 7:52pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Dynamic XAML
Posted By: ScottW
Subject: Dynamic XAML
Date Posted: 18 October 2016 at 7:59pm
My goal here is to have a Recent Items list as part of a larger markup page. The majority of the page is pre-built XAML, but I need to inject the recently used items at runtime. I can get access to the StackPanel that holds the list and add one, but the Hyperlink functionality doesn't work.

In this sample, the first item in the list is in the XAML and I am trying to add a second item that looks and works like the first time. It doesn't take on the hyperlink foreground color and it doesn't fire the events.

To duplicate this, create a VB6 form with just a MarkupLabel control named "Markup" and paste in this code:


Option Explicit

Private Sub Form_Load()

    Dim sXaml As String

            sXaml = "<Page xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' Width='800' Height='500'>"
    sXaml = sXaml & "<Border><StackPanel x:Name='RecentList'>"
    sXaml = sXaml & "<TextBlock x:Name='Recent1'  TextWrapping='Wrap' Margin='0,0,0,2'><Hyperlink x:Name='txtRecent1' Tag='Recent1' Click='HyperClick' MouseEnter='HyperEnter' MouseLeave='HyperLeave' TextDecorations='' Foreground='#2f719c'>Recent Item 1</Hyperlink></TextBlock>"
    sXaml = sXaml & "</StackPanel></Border></Page>"
   
    Markup.MarkupContext.SetHandler Me
    Markup.Caption = sXaml
   
    AddRecentEntry "Recent Item 2"
   
End Sub

Private Sub AddRecentEntry(ByVal sDB As String)

    Dim SP As MarkupStackPanel
    Dim TB As MarkupTextBlock
    Dim HL As MarkupHyperlink
   
    ' Find the recent database list
    Set SP = Markup.MarkupUIElement.FindName("RecentList")
    If Not SP Is Nothing Then

        ' Create a new Hyperlink
        Set HL = Markup.MarkupContext.CreateObject("Hyperlink")
        If Not HL Is Nothing Then
            HL.Name = "txtRecent2"
            HL.Tag = "Recent2"
            HL.AddHandler HL.ClickEvent, "HyperClick"
            HL.AddHandler HL.MouseEnterEvent, "HyperEnter"
            HL.AddHandler HL.MouseLeaveEvent, "HyperLeave"
            HL.TextDecorations = xtpMarkupTextDecorationsNone
            HL.Foreground = Markup.MarkupContext.CreateSolidBrush(&H9C712F)
        End If

        ' Create a new TextBlock
        Set TB = Markup.MarkupContext.CreateObject("TextBlock")
        If Not TB Is Nothing Then
            TB.Name = "txtRecent5"
            TB.TextWrapping = xtpMarkupTextWrap
'            TB.Margin.Bottom = 2
            TB.Text = sDB
        End If
       
        TB.Inlines.Add HL
        SP.Children.Add TB
       
    End If

End Sub


Public Sub HyperClick(ByVal Sender As MarkupObject, ByVal Args As MarkupRoutedEventArgs)
Debug.Print "Click", Sender.Name, Sender.Tag, Args.Event.Name
End Sub

Public Sub HyperEnter(ByVal Sender As MarkupObject, ByVal Args As MarkupRoutedEventArgs)
Debug.Print "Enter", Sender.Name, Sender.Tag, Args.Event.Name
End Sub

Public Sub HyperLeave(ByVal Sender As MarkupObject, ByVal Args As MarkupRoutedEventArgs)
Debug.Print "Leave", Sender.Name, Sender.Tag, Args.Event.Name
End Sub


What am I doing wrong here?

Also, not sure how to set the margins on the TextBlock since that property seems to be read-only.

Thanks!




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net