New to Telerik Test Studio? Download free 30-day trial

FrameworkElement Object

The FrameworkElement object is analogous to the FrameworkElement in Silverlight and is the base object that all visual elements and controls inherit from in the ArtOfTest.WebAii.Silverlight.UI namespace. For customers interested in our extensibility model, the Silverlight Extension does not expose a UIElement and therefore, our FrameworkElement can be viewed as the combination of Silverlight's UIElement + FrameworkElement.

The FrameworkElement and all objects that inherit from it get the following infrastructure properties:

Property Description
AbsoluteSiblingTagIndex Get the sibling tag index of this FrameworkElement.
AbsoluteTagIndex Get the absolute index of this XAML tag in the Visual Tree.
ActualHeight Gets the rendered height of a FrameworkElement.
ActualWidth Gets the rendered width of a FrameworkElement.
Application Get the Application object that owns this element.
AutomationId Gets the AutomationId set on this element if any.
Children Gets the visual children of this element.
Clip Gets or sets the Geometry used to define the outline of the contents of a UIElement.
Depth Get the depth of this element in the Visual Tree.
EnableValidateMouseLocation Enables or disables the validation of mouse click locations before performing mouse actions.
Find Get the Find object used to search the visual children of this element.
Height Gets or sets the suggested height of a FrameworkElement.
HorizontalAlignment Gets or sets the horizontal alignment characteristics applied to a FrameworkElement when it is composed within a layout parent, such as a panel or items control.
Host Returns the SilverlightApp object owning this FrameworkElement.
IsHitTestVisible Gets or sets whether the contained area of this UIElement can return true values for hit testing.
IsTestRegion Returns whether or not this FrameworkElement is contained inside a TestRegion (not supported in WebAii 2.0 Beta 2).
Language Gets or sets localization/globalization language information that applies to a FrameworkElement.
Margin Gets or sets the outer margin of a FrameworkElement.
MaxHeight Gets or sets the maximum height constraint of a FrameworkElement.
MaxWidth Gets or sets the maximum width constraint of a FrameworkElement.
MinHeight Gets or sets the minimum height constraint of a FrameworkElement.
MinWidth Gets or sets the minimum width constraint of a FrameworkElement.
Name Gets (or sets, but see Remarks) the identifying name of the object. The name provides a reference that is initially markup-compiled. After a XAML processor creates the object tree from markup, run-time code can refer to a markup element by this name.
Opacity Gets or sets the degree of the object's opacity.
OpacityMask Gets or sets the brush used to alter the opacity of regions of this object.
Projection Gets or sets the perspective projection (3-D effect) to apply when rendering this UIElement.
RenderSize Gets the final render size of a UIElement.
RenderTransform Gets or sets transform information that affects the rendering position of a UIElement.
RenderTransformOrigin Gets or sets the origin point of any possible render transform declared by RenderTransform, relative to the bounds of the UIElement.
Resources Gets the locally defined resource dictionary. In XAML, you can establish resource items as child object elements of the property element, through XAML implicit collection syntax.
Style Gets or sets an instance Style that is applied for this object during rendering.
TagNameIndex Gets the tag name index of the xaml tag name in the visual tree.
TechnologyType Get the technology type of this element. Always returns TechnologyType.Silverlight for FrameworkElement objects.
TextContent Gets the text content of this framework element if any.
UseLayoutRounding Gets or sets a value that determines whether rendering for the object and its subtree should use rounding behavior that aligns rendering to whole pixels.
User Gets the UI interaction object that allows you to interact with this framework element directly using real mouse and keyboard interactions.
VerticalAlignment Gets or sets the vertical alignment characteristics applied to a FrameworkElement when it is composed within a parent object such as a panel or items control.
Visibility Gets or sets the visibility of a UIElement. A UIElement that is not visible does not render and does not communicate its desired size to layout.
Wait Gets a VisualWait object to be used on waiting for Visual elements in the VisualTree.
Width Gets or sets the width of a FrameworkElement.
XamlTag Get the XAML tag name of this FrameworkElement. This is used for hierarchy matching and traversal.

The FrameworkElement Methods

Before describing all of the methods of the FrameworkElement object I'd like to point out the following special features:

  1. VisualTree navigation: All FrameworkElements enable you to navigate the visual tree up or down. The object exposes methods and properties like Parent, Children, NextSibling, PreviousSibling, AnySibling. The navigation also supports control sensitive navigation. For example, if you would like to find the parent 'Grid' that a certain text is contained in you do the following:

        Grid containerGrid = app.Find.ByText("SomeText").Parent("Grid").As<Grid>();
    ```
    

    OR

    If you are working with a custom control that doesn't have a strongly-typed object under ArtOfTest.WebAii.Silverlight.UI, the navigation methods all offer a non-generic version that can be used to search for a certain type. For example, let's say you are trying to find the custom control "Bar" that contains some text, then you can do the following:

        FrameworkElement barElement = app.Find.ByText("SomeText").Parent("Bar");
    ```
    

    Parent, NextSibling, PreviousSibling & AnySibling all offer a non-generic versions in addition to the generic one.

  2. User Interaction object:

    The FrameworkElement object exposes a user interaction object. The object is exposed as a property named 'User'. User then exposes all the real automation methods like moving the mouse to click an element, type a text, mouse enter, mouse leave…etc.

    Note: One of the reasons why we moved these methods into their own object under 'User.xxx' is to help users differentiate between automation that is done by setting/getting properties vs. real automation that used the mouse or keyboard to invoke actions.

  3. Element coordinates:

    All FrameworkElements offer the ability to get both the relative coordinates of the element within the Silverlight application and the actual coordinates in screen coordinates. The two methods are GetRectangle()and GetScreenRectangle().

    Note: Given that WPF/Silverlight applications allow for rich transforms for visual elements (i.e. rotate, zoom….etc) and some elements like ellipses don't really conform to a rectangle per-say, our coordinate calculations will always return the largest rectangle that contains the actual element with its center right at the center of the element. For example, a GetRectangle on an ellipse will return this:

    SL app

    The highlighting above is using the FrameworkElement.Highlight() method.

  4. XML Representation:

    Every FrameworkElement has a ToXml() method on it that returns the VisualTree of that element as an XML formatted string. This is very useful when trying to understand the visual tree at a certain state. [Hint: You can get the entire visual tree of an app by calling app.VisualTree.Root.ToXml()]

These are all of the FrameworkElement methods available for use by your automation code:

Method Description
AnySibling(T) Return any sibling of this control of type T. The framework first searches for a previous sibling having the specified type. If it finds one that sibling is returned. If it doesn't find one then it searches for the next sibling. If it find one that sibling is returned, otherwise null (Nothing in VB.NET) is returned.
As(T) Return this framework element as a strongly-typed control of type T.
CastAs(T) Returns this framework element as a strongly-typed control of type T without enforcing tag name to match the type it is being cast to. This functions gives you free casting abilities between types.
Equals Determines whether this FrameworkElement is equal to another, by comparing their AutomationReferences.
GetChildren Get the children of this framework element.
GetNextSibling Get the next sibling of this FrameworkElement.
GetParent Get the Parent of this element.
GetPrevSibling Get the previous sibling.
GetRectangle Get the bounding rectangle of this FrameworkElement within the owning Silverlight application.
GetScreenRectangle Return the actual coordinates of this element in absolute screen coordinates taking into account the location of the overall plug-in on the page.
Highlight Highlight this element in the Silverlight application.
NextSibling Get the next sibling control of a specific type.
Parent Get the parent FrameworkElement of this element.
PreviousSibling Get the previous sibling control of a specific type.
Refresh Refresh this FrameworkElement within the VisualTree.
ScrollToVisible Scrolls the web page so that this element is visible in the browser window.
ToXml Gets an XML formatted string that represents this element and all its children This XML represents the VisualTree.
In this article