1

I'm using a Popup to show validation messages to the User. If the element (e.g. a Textbox) is scrolled out of the View the following Method is working great and i can easy hide the Popup.

Determine control is Visible

But if i move the window partial out of the screen so i can't see the element anymore this Method still returns true. In this case the popup is still visibile to the User (The popup allways stays within screen bounds) but the element is not.

How can i check if a element is visibile within the screen?

Community
  • 1
  • 1
outofBounds
  • 594
  • 6
  • 18

1 Answers1

2

This can be done using PrimaryScreenWidth and PrimaryScreenHeight available in SystemParameters. You need to calculate the position of control relative to screen and check whether that point exist in screen bounds.

Point locationFromWindow = this.textBox.TransformToVisual(this).Transform(new Point(0, 0)); 
Point point = this.textBox.PointToScreen(new Point(0, 0));
Rect rect = new Rect(0, 0, SystemParameters.PrimaryScreenWidth, SystemParameters.PrimaryScreenHeight);
if (!rect.Contains(point))
{
    // Outside screen bounds.
}
Jawahar
  • 4,775
  • 1
  • 24
  • 47