How to determine Popup Placement

5 posts, 0 answers
  1. Robert
    Robert avatar
    271 posts
    Member since:
    Mar 2011

    Posted 24 Aug 2012 Link to this post

    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
  2. Robert
    Robert avatar
    271 posts
    Member since:
    Mar 2011

    Posted 24 Aug 2012 Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Robert
    Robert avatar
    271 posts
    Member since:
    Mar 2011

    Posted 24 Aug 2012 Link to this post

    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;
    }

  5. Boby
    Admin
    Boby avatar
    595 posts

    Posted 28 Aug 2012 Link to this post

    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.

  6. Robert
    Robert avatar
    271 posts
    Member since:
    Mar 2011

    Posted 30 Aug 2012 Link to this post

    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!
Back to Top
UI for WPF is Visual Studio 2017 Ready