Search

Can't get UIAutomationElement BoundingRectangle in win7 by suriyel

Closed
as External Help for as External

1
0
Sign in
to vote
Type: Bug
ID: 778466
Opened: 2/4/2013 7:49:33 AM
Access Restriction: Public
0
Workaround(s)
0
User(s) can reproduce this bug
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.


Details (expand)

Visual Studio/Team Foundation Server/.NET Framework Tooling Version

.NET Framework 4.5

Steps to reproduce


1,Creat a simple datagridview using the interface IRawElementProviderFragment.
2,You can use the UISpy to get the tableCell or get BoundingRetangle whith automationElement.

Product Language

Chinese - Simplified

Operating System

Windows 7

Operating System Language

Chinese (Simplified)

Actual results

UISpy or process which use automationElement to get BoundingRetangle stops working.

Expected results

UISpy or automationElement can get BoundingRetangle
File Attachments
File Name Submitted By Submitted On File Size  
WindowsFormsApplication2.rar 2/4/2013 1.8 MB
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)
Sign in to post a workaround.