Why does the this popup think it is encountering the edge of the screen?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Why does the this popup think it is encountering the edge of the screen?



The Popup Placement Behavior Guide shows how to position a popup using several properties:



Using these, we can set the target area, target origin, and placement alignment point. The guide goes on to describe a whole host of conditions for how the popup is placed in the event that it encounters the screen.



In my application, I created a popup programmatically as a response to user input and set the properties:


private void Button_Click(object sender, RoutedEventArgs e)

Popup popup = new Popup();
popup.Child = new PopupContent();
popup.Placement = PlacementMode.Right;
popup.PlacementTarget = redRectangle;

popup.StaysOpen = false;
popup.IsOpen = true;



The intended behavior was that the popup would appear on the right of rectangle. Instead I got this:



Incorrect Popup Placement




<Window x:Class="PopupTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Width="700" Height="700">
<Grid>
<Button Click="Button_Click" Content="Create Popup" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="83" Height="25"/>
<Rectangle x:Name="redRectangle" Width="20" Height="20" Fill="Red"/>
</Grid>
</Window>




<UserControl x:Class="PopupTest.PopupContent"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="300" Height="300">
<Border BorderBrush="Black" BorderThickness="2">
<Border BorderBrush="#FF50A0E0" BorderThickness="10" Background="White">
<Border BorderBrush="Black" BorderThickness="2" Padding="10">
<Label Content="Popup!" FontSize="70" VerticalContentAlignment="Center" HorizontalContentAlignment="Center"/>
</Border>
</Border>
</Border>
</UserControl>





There's not enough room on the right side of that rectangle for the entire dialog to fit on the screen, unless you haven't shown us the whole screen.
– Robert Harvey
Aug 10 at 20:24






You'd think that might be the case; however if you resize the window it still is placed to the left.
– Nick Miller
Aug 10 at 20:26





I can't reproduce your issue. Which version on the .NET Framework and Windows are you on
– mm8
Aug 13 at 12:35





Hi @mm8, I'm using .NET 4.6.1. One thing I did notice was that there needs to be enough room to display the popup on the left, otherwise the popup is coerced to the right.
– Nick Miller
Aug 13 at 12:57





I have .NET 4.7.1 installed and running your code the Popup is always displayed to the right of the rectangle as expected.
– mm8
Aug 13 at 12:59










By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard