Can't get UIAutomationElement BoundingRectangle in win7 - by suriyel

Status : 

  External<br /><br />
		This item may be valid but belongs to an external system out of the direct control of this product team.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


1
0
Sign in
to vote
ID 778466 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 2/4/2013 7:49:33 AM
Access Restriction Public

Description

Hi,
I use IRawElementProviderFragment for testing,but I can't get UIAutomationElement's BoundingRectangle in win7.When I try to get it,the process stop working.
The following code is how I get the BoundingRectangle in my tableCell using the interface of IRawElementProviderFragment:


        /// <summary>
        /// Gets the bounding rectangle of this element.
        /// </summary>
        /// <value></value>
        /// <returns>The bounding rectangle, in screen coordinates.</returns>
        System.Windows.Rect IRawElementProviderFragment.BoundingRectangle
        {
            get
            {
                var cellPoint = _grid.GetCellDisplayRectangle(_cell.ColumnIndex, _cell.RowIndex, true);
                var formPoint = new Point(cellPoint.X, cellPoint.Y);
                _grid.Invoke(new Action(() => formPoint = _grid.PointToScreen(formPoint)));
                var topPoint = new CursorPoint() { X = formPoint.X, Y = formPoint.Y };
                var widthPoint = new CursorPoint() {X = cellPoint.Width + formPoint.X, Y = formPoint.Y};
                var heightPoint = new CursorPoint() {X = formPoint.X, Y = formPoint.Y + cellPoint.Height};
                _grid.Invoke(new Action(() =>
                    {
                        try
                        {
                            LogicalToPhysicalPoint(_grid.Handle, ref topPoint);
                            LogicalToPhysicalPoint(_grid.Handle, ref widthPoint);
                            LogicalToPhysicalPoint(_grid.Handle, ref heightPoint);
                        }
                        catch (Exception)
                        {
                            ;
                        }
                    }));
                var width = widthPoint.X - topPoint.X;
                var height = heightPoint.Y - topPoint.Y;
                return new System.Windows.Rect(topPoint.X, topPoint.Y, width, height);
            }
        }
The following code is how I get the BoundingRectangle:
System.Windows.Rect boundingRect1;
object boundingRectNoDefault =
    autoElement.GetCurrentPropertyValue(AutomationElement.BoundingRectangleProperty, true);
if (boundingRectNoDefault == AutomationElement.NotSupported)
{
   return null;
}
else
{
    boundingRect1 = (System.Windows.Rect)boundingRectNoDefault;
}



And I notice the article about the dpi.But it still dosen't work.
                                                                                                  Best wishes.


Sign in to post a comment.
Posted by Microsoft on 3/5/2013 at 9:44 AM
Thank you for reporting this issue. Customer feedback is a critical part of a successful, impactful software product.
It seems that the issue is actually in implementation of :
object IRawElementProviderSimple.GetPropertyValue(int propertyId)
In ICommonTable.cs file.

else if (propertyId == AutomationElementIdentifiers.LocalizedControlTypeProperty.Id ||
                     propertyId == AutomationElementIdentifiers.ControlTypeProperty.Id)
            {
             // return ControlType.DataItem.Id;
                return ControlType.DataItem.LocalizedControlType;
            }

"LocalizedControlTypeProperty" value should be a known string, see the following MSDN article:
http://msdn.microsoft.com/en-us/library/system.windows.automation.automationelement.localizedcontroltypeproperty.aspx

After I replaced "return ControlType.DataItem.Id" with " return ControlType.DataItem.LocalizedControlType;", UI Automation client no longer hangs.

If you have additional questions, please follow up on UI Automation connect site or forum found here: http://www.microsoft.com/communities/forums/default.mspx where Microsoft and other members of the community can recommend ways of achieving the behavior you are interested in.
 
Thank you,
The Windows Forms Product Team
Posted by Microsoft on 2/4/2013 at 11:58 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Microsoft on 2/4/2013 at 8:50 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)