[WPF/VB.net] Add event programmatically to hyperlink
I making on chat app with VB.net+WPF and I need hyperlinks in that. For chat log I using RichTextBox and I adding new paragraph every time when new message come. So problem is, when I add hyperlink in RichTextBox it's not work because need CLICK event.
So, when I manually insert in my RichTextBox this:
Code:
<Hyperlink NavigateUri="http://www.google.com">Google</Hyperlink>
And use this event:
Code:
Public Sub New()
InitializeComponent()
[AddHandler](Hyperlink.RequestNavigateEvent, New RoutedEventHandler(AddressOf OnNavigationRequest))
End Sub
Public Sub OnNavigationRequest(ByVal sender As Object, ByVal e As RoutedEventArgs)
Dim source = TryCast(e.OriginalSource, Hyperlink)
If source IsNot Nothing Then
Process.Start(source.NavigateUri.ToString())
End If
End Sub
IT WORK !
But I need it programmatically
When I do it link this:
Code:
Dim PARAGRAF As Paragraph = New Paragraph
PARAGRAF.LineHeight = 1
Dim r As New Run("stefanACM: ")
r.FontFamily = New System.Windows.Media.FontFamily("/MY APP;component/Fonts/#Arial")
r.FontSize = 14
r.FontStyle = System.Windows.FontStyles.Normal
r.FontWeight = System.Windows.FontWeights.Bold
r.Foreground = bojaNick
Dim r1 As New Run("test")
r1.FontFamily = New System.Windows.Media.FontFamily("/MY APP;component/Fonts/#Arial")
r1.FontSize = 14
r1.FontStyle = System.Windows.FontStyles.Normal
r1.FontWeight = System.Windows.FontWeights.Bold
r1.Foreground = bojaText
Dim r2 As New Run("HYPERLINK ")
Dim h As New Hyperlink(r2)
h.NavigateUri = New Uri("http://www.google.com")
PARAGRAF.Inlines.Add(r)
PARAGRAF.Inlines.Add(r1)
PARAGRAF.Inlines.Add(h)
txtLog.Document.Blocks.Add(PARAGRAF)
When I click on HYPERLINK nothing happen...
Can anybody help me with this. I think something stupid is problem but I am tired and can't find that :|
Thanks in advice
Re: [WPF/VB.net] Add event programmatically to hyperlink
I can't believe...
I put transparent image over chat and that's why click event didn't activated :|
Now it's work...