Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > ActiveX COM > MarkupLabel Control
  New Posts New Posts RSS Feed - Dynamic XAML
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Dynamic XAML

 Post Reply Post Reply
Author
Message
ScottW View Drop Down
Groupie
Groupie


Joined: 02 August 2005
Status: Offline
Points: 82
Post Options Post Options   Thanks (0) Thanks(0)   Quote ScottW Quote  Post ReplyReply Direct Link To This Post Topic: Dynamic XAML
    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!

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.188 seconds.