A
A
Alexander2018-05-02 08:52:47
.NET
Alexander, 2018-05-02 08:52:47

How to get window coordinates?

Found a similar question , but none of the answers worked for me.
1) this.Leftand this.Top- the studio writes that these are not numbers (I believe that ∞)
2) throws an error: System.InvalidOperationException: "This Visual element is not connected to PresentationSource." PS If it matters, then my Window has the following properties:PointToScreen(new Point(this.Left, this.Top))

AllowsTransparency="true" Background="Transparent" WindowStyle="None"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2018-05-03
@AlexNineteen

As it turned out, you really need to call the Show() function and then everything will work (thanks to Alexey Pavlov for the tip)
Now I have the following code:

public MainWindow()
{
    InitializeComponent();

    this.Show();
     // PointToScreen работает корректно
    var a =  PointToScreen(new Point(Left, Top)).ToString();
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question