How to create a WPF popup in the lower right corner of the application?

I am using a WPF Popup control. I want it to appear inside my application window, docked in the lower right corner of the window. The actual height and width of the popup will change depending on the message displayed.

If that matters, the contents of the popup are the border, wrapping the StackPanel while holding a few text blocks.

Thanks for any help.

+5
source share
3 answers

It is rather complicated and there is no easy answer. To your question you indicate:

The actual height and width of the popup will vary depending on the message that is displayed.

You should not worry, this is the default behavior of WPF Popup.

, :

  • PlacementTarget
  • , . , , .

Popup .

0

PlacementTarget, Placement = Left, Horizontal/VerticalOffset

<Popup IsOpen="{Binding ElementName=togglebutton, Path=IsChecked, Mode=TwoWay}"
       PlacementTarget="{Binding ElementName=togglebutton}"
       Placement="Left"
       HorizontalOffset="{Binding ActualWidth, ElementName=togglebutton}"
       VerticalOffset="{Binding ActualHeight, ElementName=togglebutton}">
+4

I just did something like this and it really is not that difficult, but it requires special placement of your popup. When you announce your popup, simply set the PlacementMode property to Custom, and then set the CustomPopupPlacementCallback property to the method you want to use.

this.trayPopup.CustomPopupPlacementCallback = GetPopupPlacement;

private static CustomPopupPlacement[] GetPopupPlacement(Size popupSize, Size targetSize, Point offset)
{
    var point = SystemParameters.WorkArea.BottomRight;
    point.Y = point.Y - popupSize.Height;
    return new[] { new CustomPopupPlacement(point, PopupPrimaryAxis.Horizontal) };
}
+2
source

All Articles