This is a migrated thread and some comments may be shown as answers.

How to determine Popup Placement

4 Answers 631 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 24 Aug 2012, 10:31 AM
Hi,

Before I begin, this is more of a question about a Popup control rather than the RadRichTextBox itself. Feel free to move this post if you think it should belong in a different section.
I've been creating my own RadRichTextBox Intellisense application where I'm positioning a Popup control based upon the caret position.

I know how to obtain the position of the caret, like so:
Point position = new Point();
 
if (!richTextBox.Document.CaretPosition.Location.IsEmpty)
{
    position = richTextBox.ActiveEditorPresenter.GetViewPointFromDocumentPosition(richTextBox.Document.CaretPosition);
 
    position.Offset(offsetX, offsetY);
    return position;
}

The problem I have is that the Popup placement will alter depending on the size of the Popup/ListBox and if it is positioned towards the top or bottom of the screen.

When the the Popup is showing above my position point (the caret is  the bottom of the screen) it is aligned in the correct place. However, should the caret be towards the top of the screen, the top edge of the Popup is aligned with the top of the caret.

You can better see what I mean from the attached images.

I need to some way to determine if the popup placement is Above or Below my point and adjust the vertical offset accordingly.

Thank you for your time,

Rob

4 Answers, 1 is accepted

Sort by
0
Robert
Top achievements
Rank 1
answered on 24 Aug 2012, 02:49 PM
Here's the XAML for my Intellisense Popup ListBox

<Popup x:Name="autoCompletePopupWindow"
       MaxHeight="300"
       VerticalAlignment="Bottom"
       Placement="RelativePoint">
      
    <telerik:RadListBox x:Name="radListBox"
                        Visibility="Collapsed"
                        TextPath="Name"
                        ItemTemplate="{StaticResource AutoCompleteListBoxTemplate}"
                        ItemsSource="{Binding autoCompleteListItems}"
                        MouseDoubleClick="radListBox_MouseDoubleClick"
                        MouseUp="radListBox_MouseUp">
    </telerik:RadListBox>
     
    <Popup.Effect>
        <DropShadowEffect ShadowDepth="10" Color="Gray" Opacity=".4" Direction="320" RenderingBias="Performance" />
    </Popup.Effect>
</Popup>

And here's my method to adjust the position:

private void AutoCompleteAdjustPosition()
{
    Point position = RadDocumentAutoComplete.GetCaretPositionWithOffset(this.radRichTextBox, 0, 0);
 
    autoCompletePopupWindow.HorizontalOffset = position.X;
    autoCompletePopupWindow.VerticalOffset = position.Y;
}

I can't for the life of me work out how you tell if the Popup window is going UP from the specified point or DOWN.
0
Robert
Top achievements
Rank 1
answered on 24 Aug 2012, 03:07 PM
I have tried to get the PlacementRectange.BottomLeft value and compare it with position.Y value but it's always Infinite.

if (autoCompletePopupWindow.PlacementRectangle.BottomLeft.Y < position.Y)
{
    autoCompletePopupWindow.VerticalOffset = autoCompletePopupWindow.VerticalOffset + 20;
}

0
Boby
Telerik team
answered on 28 Aug 2012, 06:16 AM
Hello Robert,
You could try to alter popup placement settings, as described in MSDN here and here, trying to avoid automatic repositioning.


Regards,
Boby
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Robert
Top achievements
Rank 1
answered on 30 Aug 2012, 03:00 PM
Thanks for getting back to me. I will look into your suggestion.

I've come to realise that the WPF Popup sucks a little bit. For some reason you are unable to control the Z-Index of the Popup and thus it always overlays every window, even if the window belongs to another application. Very frustrating!
Tags
RichTextBox
Asked by
Robert
Top achievements
Rank 1
Answers by
Robert
Top achievements
Rank 1
Boby
Telerik team
Share this question
or