Asked by:

PopUp with HorizontalAlignment=Right behaves strangely

Question

If my XAML has a PopUp in the SwapChainBackgroundPanel with HorizontalAlignment="Right" then it sits outside the right edge of the SCBP (the PopUp's left edge is along the right edge of the SCBP). You can see this in Blend window in VS2012 Pro. The
PopUp has a width determined by its contents and looks ok, it's just off the right side of the screen. Here's the XAML showing the problem:

However, if I add Width="300" to the PopUp declaration, leaving the same HorizontalAlignment="Right" in there, the PopUp is correctly positioned inside the SCBP (the PopUp's right edge is parked against the right side of the SCBP as you'd expect). Here's
that example:

Why does setting the Width in the PopUp declaration cause the HorizontalAlignment to work correctly? It's almost like XAML thinks the PopUp has a width of zero without the Width="300" part, even though it shows the contents correctly.

Very confusing!

Thanks

Edit: note that the VerticalAlignment behaves similarly. If I set it to "Bottom" without giving an explicit Height to the PopUp, the PopUp appears offscreen to the bottom.