0

I have a text with hyperlinks in it. To not irritate the reader I want to have the normal text and the links on the same line. Right now every Inline element starts a new line.

It displays:

Please visit

http://google.com

to continue.

I want:

Please visit http://google.com to continue.

I've also noticed, that the hyperlink Hit area cover the hole inline element and not just the text.

My problem is identical than described and solved here: Add clickable hyperlinks to a RichTextBox without new paragraph

The problem is, that it seems than something like a flowdocument for wp8 doesn't exist. I need to create the inline elements programatically.

EDIT 1:

Here my code how I add the inline elements:

                    int index = 0;
                    rt = new RichTextBox() { };

                    while (true)
                    {
                        Paragraph para = new Paragraph();
                        if (item.text.Substring(index).IndexOf("<") == 0)
                        {
                            //TRUE when link 
                            //I extract the URL and the linktext, and also update the index

                            Hyperlink hyper = new Hyperlink();
                            hyper.Click += new RoutedEventHandler((sender,e) => Hyperlink_Click(sender,e,URL));
                            hyper.Inlines.Add(linktext);
                            para.Inlines.Add(hyper);
                        }
                        else if (item.text.Substring(index).Contains("<"))
                        {
                            //TRUE when text, item.text contains a link
                            // I extract the text and update index
                            Run run = new Run() { Text = text };
                            para.Inlines.Add(run);
                        }
                        else
                        {
                            //TRUE when only text is left
                            Run run = new Run() { Text = item.text.Substring(index) };
                            para.Inlines.Add(run);
                            rt.Blocks.Add(para);
                            break;
                        }
                        // REMOVE: rt.Blocks.Add(para);
                    }
                    rt.SetValue(Grid.RowProperty, MainViewer.RowDefinitions.Count - 1);
                    MainViewer.Children.Add(rt);

EDIT 2

I still couldn't solve this Problem, does no one know a solution? I saw what I want in an App before, so it must be possible.

EDIT 3

I've created for every inline element a new paragraph. I've fixed my code above, it is working now

Community
  • 1
  • 1
Florian Moser
  • 2,583
  • 1
  • 30
  • 40
  • When you set it in code it should not add a new line... maybe take a look at the TweetStatusConverter class in this project by Bjorn Kuiper http://bjorn.kuiper.nu/2012/03/19/wp7-tweetsharp-and-agfx/ is does something similar! – Depechie Mar 24 '14 at 10:44
  • I create the RichTextBox at the same pattern that the author in this project. I will post my code soon, but right now I have a lot of other things to do. Thanks for your help so far. – Florian Moser Mar 24 '14 at 18:55
  • Good luck with the app! – Depechie Mar 25 '14 at 10:39

1 Answers1

0
Paragraph p = new Paragraph();
p.Inlines.Add("Plase visit ");
var link = new Hyperlink();
link.Inlines.Add("google.com ");
p.Inlines.Add(link);
p.Inlines.Add("to continue");
rtb.Blocks.Add(p);

this works fine for me.

PS If you want to show some html in you app, you can use HTMLTextBox or HTMLViewer from http://msptoolkit.codeplex.com/

ad1Dima
  • 3,185
  • 2
  • 26
  • 37
  • My mistake was that I added a new paragraph for every Inline object. This helped me found the bug. I've fixed my code. I dont want to use pure html, because I have a hard time with adding css (I've had the case, that some styles are not shown, while at the same time my desktop browser shows what I intended to do). I prefer extracting the tags. A bit more work of course, but less frustration, because I always know where something can go wrong. – Florian Moser Apr 01 '14 at 13:12