How to show a popup under a hyperlink in richtextbox with exact position?

2 posts, 0 answers
  1. kun
    kun avatar
    3 posts
    Member since:
    Jan 2016

    Posted 14 Jan Link to this post

    Holle

     We used a listbox as a popup to show drop-down box under the hyperlinks in Radrichtextbox, but we can not locate the position of the listbox (drop-down box). We located the position at the Caret now, but this did not meet our requirement. We plan to locate the position at the start of a hyperlink, could you please help us.

    What we should explain is that: the language we used is Chinese, far from English words, there is no space between Chinese words in a sentence, 

    the English sentences: Telerick is a very good company.

    but in Chinese, the sentence is: Telerick是一个非常好的公司

    We located the position of caret, and calculated the length between the start and the end of hyperlink, and put the listbox at the position :caret-the length. But the listbox always display in a wrong position..

    Thanks a lot, we hope your answer.

     

     

     

     

     

  2. Todor
    Admin
    Todor avatar
    168 posts

    Posted 19 Jan Link to this post

    Hello kun Wang,

    Setting the associated to the Hyperlink's annotation markers LayoutBox's bounding rectangle as a Popup's PlacementRectangle should do the job in your case. However, if RadRichTextBox is not in its default Flow layout mode, but in Paged layout mode instead, you should modify that bounding rectangle a bit in order the "gaps" between the Document and ScrollBars to be taken into account. 

    For example, you could use the following code snippet when the Popup should be opened in order to show it under the hyperlink:
    HyperlinkRangeStart hyperlink = this.radRichTextBox.Document.EnumerateChildrenOfType<HyperlinkRangeStart>().LastOrDefault();
    if (hyperlink != null)
    {
        LayoutBox hyperlinkLayoutBox = hyperlink.GetAssociatedLayoutBoxes().FirstOrDefault();
     
        Popup popup = new Popup();
        popup.PlacementTarget = this.radRichTextBox;
        popup.Width = 200;
        popup.Height = 200;
        //popup.Child = Set the Popup's content child...
     
        Rect placementRectangle = hyperlinkLayoutBox.ControlBoundingRectangle.ToRect();
        if (this.radRichTextBox.LayoutMode == DocumentLayoutMode.Paged)
        {
            double y = placementRectangle.Y - this.radRichTextBox.VerticalOffset + placementRectangle.Height;
            double x = placementRectangle.X + (this.radRichTextBox.ActualWidth - this.radRichTextBox.Document.DocumentLayoutBox.BoundingRectangle.Width) / 2;
        
            placementRectangle = new Rect(x, y, placementRectangle.Width, placementRectangle.Height);
        }
     
        popup.PlacementRectangle = placementRectangle;
        popup.IsOpen = true;
    }

    Please note, it might be necessary to change the "x" and "y" calculations depending on your scenario.

    I hope this helps.

    However, if you have other questions or any further problems with the implementation of the above-mentioned rectangle's calculations, please try to isolate the issue in a sample project and send it to us. In this way, it will be much easier for us to help you to achieve the desired goal.

    Regards,
    Todor
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top