locked
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:

    <Popup HorizontalAlignment="Right">
        <Grid Width="300" Height="200" Background="Black">
            <TextBlock Text="Hello" FontSize="24" Foreground="White"/>
        </Grid>
    </Popup>
     

    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:

    <Popup HorizontalAlignment="Right" Width="300">
        <Grid Width="300" Height="200" Background="Black">
            <TextBlock Text="Hello" FontSize="24" Foreground="White"/>
        </Grid>
    </Popup>
    

    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.


    • Edited by henador Monday, August 27, 2012 6:37 AM Added examples and VerticalAlignment mention
    Monday, August 27, 2012 6:28 AM

All replies

  • That is curious behavior. Checking to see if that is indeed by design.

    Update: A bug has been filed to determine if this was the expected behavior or if it is expected and needs documented.


    David Lamb


    Wednesday, August 29, 2012 1:37 AM
    Moderator