Size Structure
Collapse the table of content
Expand the table of content

Size Structure

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Describes the width and height of an object.

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.

public struct Size
<Size ...>width,height</Size>
<object property="width,height"/>

XAML Values


A numeric value greater than or equal to 0 that specifies the Width of the Size structure.


A numeric value greater than or equal to 0 that specifies the Height of the Size structure.

In the XAML syntax, the width-height delimiter can be either a space or comma. A Size value uses an internal type converter to process the string value.

See Remarks for additional information on value constraints that apply both to XAML and to code.

The Size type exposes the following members.

Public methodSizeInitializes a new instance of the Size structure and assigns it an initial width and height.

Public propertyStatic memberEmptyGets a value that represents a static empty Size.
Public propertyHeightGets or sets the height of this instance of Size.
Public propertyIsEmptyGets a value that indicates whether this instance of Size is Empty.
Public propertyWidthGets or sets the width of this instance of Size.

Public methodEquals(Object)Compares an object to an instance of Size for equality. (Overrides ValueType.Equals(Object).)
Public methodEquals(Size)Compares a value to an instance of Size for equality.
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeGets the hash code for this instance of Size. (Overrides ValueType.GetHashCode().)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string representation of this Size. (Overrides ValueType.ToString().)

Public operatorStatic memberEqualityCompares two instances of Size for equality.
Public operatorStatic memberInequalityCompares two instances of Size for inequality.

Dimensions of 0 are permitted by the Size structure, but might not be permitted when interpreted or validated by particular properties that take a Size. Check documentation for the specific property you are setting for possible details on Size property constraints. In general, the values of a Size can be greater than or equal to 0.

The programmatic upper limit for values is not PositiveInfinity, it is a lower number (approximately 1,000,000) that is enforced by the Windows Phone native code.

Although the type of the property values of a Size is Double, you generally should use integer values.

Rect is a similar structure that uses the same metaphor of specifying a height and width. However, a Rect specifies an origin point, whereas a Size does not. In general, Rect is used for APIs that relate to graphical presentation at a lower level, and Size is used for APIs that relate to UI presentation and layout.

In contrast to other structures such as Thickness, the XAML attribute syntax for Size does not support a symmetric mode that takes only one value applied to both width and height. For instance the following will generate a parser error: <ArcSegment Size="50"/>.

Negative values for height or width of a Size are not permitted.

Properties of Size do not support an attribute syntax in XAML for Windows Phone. In XAML you should always specify Size-type properties through one of the following usages:

  • The XAML attribute usage, which infers properties that use the Size type and uses a type converter to process the attribute string into the specific values for the Size.

  • A property element usage, containing a Size object element. For that object element, set the Size properties using initialization text, as shown in the XAML Object Element Usage.

If you specify a Size for use as a resource, use the object element usage and set the Size properties using initialization text.

JavaScript API Notes

There is no object representation for a Size available in the JavaScript API for Windows Phone; after being input as a string either through XAML or as a JavaScript property, a Size becomes an internal object representation.

Size is available as a valid object in the managed API for Windows Phone.

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

© 2018 Microsoft