Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- How to set the links in a text block clickable in wp7
- <TextBlock>
- <Run>Pure Text</Run>
- <HyperLink Command="{Binding HyperLinkTapped}">http://google.com</HyperLink>
- <Run>Pure Text Again</Run>
- </TextBlock>
- private void OnMessageReceived(string message)
- {
- var textBlock = new RichTextBox()
- {
- TextWrapping = TextWrapping.Wrap,
- IsReadOnly = true,
- };
- var paragraph = new Paragraph();
- var runs = new List<Inline>();
- foreach (var word in message.Split(' '))
- {
- Uri uri;
- if (Uri.TryCreate(word, UriKind.Absolute, out uri) ||
- (word.StartsWith("www.") && Uri.TryCreate("http://" + word, UriKind.Absolute, out uri)))
- {
- var link = new Hyperlink();
- link.Inlines.Add(new Run() { Text = word });
- link.Click += (sender, e) =>
- {
- var hyperLink = (sender as Hyperlink);
- new WebBrowserTask() { Uri = uri }.Show();
- };
- runs.Add(link);
- }
- else
- {
- runs.Add(new Run() { Text = word });
- }
- runs.Add(new Run() { Text = " "});
- }
- foreach (var run in runs)
- paragraph.Inlines.Add(run);
- textBlock.Blocks.Add(paragraph);
- MessagesListBox.Children.Add(textBlock);
- MessagesListBox.UpdateLayout();
- }
Advertisement
Add Comment
Please, Sign In to add comment