Popup with placement mode as relative renders in wrong position on some machines.
Hi Team,
WPF Popup with placement mode as relative renders in wrong position on some machines. As per the behavior it must be rendered on the left top corner and inside the placement target layout, but it renders outside the placement target layout. Please refer the following image and machine configuration,
Machine configuration:
- Laptop model: Dell Latitude 3490 and Lenovo Yoga 510
- OS: Windows 10 Pro
- .Net Framework: 4.7 and 4.8
- Visual studio: 2017 and 2019
On some machines it works as per the behavior, left top corner and inside the placement target layout. Please refer the following image and machine configuration.
Machine configuration
- Laptop model: Dell Latitude 5501 and ASUS VivoBook 14 X409FA-EK555T
- OS: Windows 10 Pro
- .Net Framework: 4.7 and 4.8
- Visual studio: 2017 and 2019
Code snippet:
Xaml
<Grid x:Name="innerLayout" Background="Yellow" HorizontalAlignment="Center" VerticalAlignment="Center" Height="300" Width="400" />
C#
public partial class MainWindow : Window
{
private Popup relativePopup;
private TextBlock textBlock;
private UserControl contentcontrol = new UserControl();
public MainWindow()
{
InitializeComponent();
this.relativePopup= new Popup();
this.ShowPopupOnInitialLoad();
}
internal virtual void ShowPopupOnInitialLoad()
{
this.relativePopup.AllowsTransparency = true;
this.relativePopup.PlacementTarget = this.innerLayout;
this.relativePopup.Placement = PlacementMode.Relative;
this.relativePopup.Height = 50;
this.relativePopup.Width = 100;
this.relativePopup.SnapsToDevicePixels = true;
if (textBlock == null)
{
textBlock = new TextBlock();
textBlock.Text = "Relative Popup";
textBlock.Background = Brushes.Blue;
textBlock.Foreground = Brushes.White;
textBlock.SnapsToDevicePixels = true;
contentcontrol.Content = textBlock;
}
this.relativePopup.Child = contentcontrol;
textBlock.Height = 50;
textBlock.Width = 100;
this.relativePopup.IsOpen = true;
}
}
Could you please check and provide a solution for this?