System.Windows.Rect.Contains C# (CSharp) Method

Contains() public method

public Contains ( Rect rect ) : bool
rect Rect
return bool
        public bool Contains(Rect rect)
        {
            if (this.IsEmpty || rect.IsEmpty)
            {
                return false;
            }
            return ((((this._x <= rect._x) && (this._y <= rect._y)) && ((this._x + this._width) >= (rect._x + rect._width))) && ((this._y + this._height) >= (rect._y + rect._height)));
        }

Same methods

Rect::Contains ( Point point ) : bool
Rect::Contains ( double x, double y ) : bool

Usage Example

Example #1
1
 /// <summary>
 /// Returns a value indicating whether a point is inside the bounding box of the element.
 /// </summary>
 /// <param name="element"></param>
 /// <param name="pointRelativeToElement"></param>
 /// <returns></returns>
 public static bool ContainsPoint(this FrameworkElement element, Point pointRelativeToElement)
 {
     //TODO: Silverlight allows more complex geometries than Rectangle.
     Rect rect = new Rect { X = 0, Y = 0, Width = element.ActualWidth, Height=element.ActualHeight };
     
     return rect.Contains(pointRelativeToElement);            
 }
All Usage Examples Of System.Windows.Rect::Contains