Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a WPF popup appear in the lower right corner of an application?

Tags:

wpf

I am using a WPF Popup control. I want it to appear inside my application window, anchored in the bottom right corner of the window. The actual height and Width of the popup will change depending on the message that is being displayed.

If it matters, the content of the popup are a Border, wrapping a StackPanel, holding multiple TextBlocks.

Thank you for any help.

like image 601
Sako73 Avatar asked Sep 06 '11 01:09

Sako73


2 Answers

Use 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}">
like image 174
Klaus Fischer Avatar answered Oct 12 '22 03:10

Klaus Fischer


I just did something like this, and it's really not that tricky, but it does require custom placement of your popup. When you declare your popup just set the PlacementMode property to Custom, 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) };
}
like image 25
EricTheRed Avatar answered Oct 12 '22 02:10

EricTheRed