Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF Popup Control - Find X, Y Coordinates
    primarykey
    data
    text
    <p>I'm trying to get the X,Y coordinates of a popup control. I have tried:</p> <p>VisualTreeHelper.GetOffset(Popup);</p> <p>but the vector returned always contains (0,0) for X and Y.</p> <p>The parent of the popup is the layout root, which is a grid.</p> <p>The CustomPopupPlacementCallback also always returns 0,0 for it's Point parameter.</p> <p>The goal is to allow the user to drag the popup anywhere on the screen. I was going to try and accomplish this by getting the current popup and mouse position, and moving the popup in the same direction of the mouse moves.</p> <p>--------------------Update--------------------</p> <p>Chris Nicol, I have tried your answer with the following code, but still receive 0,0 for rootPoint:</p> <p>Xaml:</p> <pre><code>&lt;Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="Test.MainWindow" x:Name="Window" Title="MainWindow" Width="800" Height="600"&gt; &lt;Grid x:Name="LayoutRoot"&gt; &lt;Popup x:Name="Popup" IsOpen="True" Placement="Center" Width="100" Height="100"&gt; &lt;Button Click="Button_Click" Content="Test" /&gt; &lt;/Popup&gt; &lt;/Grid&gt; </code></pre> <p></p> <p>Code Behind:</p> <pre><code>public partial class MainWindow : Window { public MainWindow() { this.InitializeComponent(); // Insert code required on object creation below this point. } private void Button_Click(object sender, RoutedEventArgs e) { GeneralTransform transform = Popup.TransformToAncestor(LayoutRoot); Point rootPoint = transform.Transform(new Point(0, 0)); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload