Udostępnij za pośrednictwem


Size Structure

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Describes the width and height of an object.

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public Structure Size
public struct Size
<Size ...>width,height</Size>
<object property="width,height"/>

XAML Values

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

  • height
    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.

Constructors

  Name Description
Public methodSupported by Silverlight for Windows Phone Size Initializes a new instance of the Size structure and assigns it an initial width and height.

Top

Properties

  Name Description
Public propertyStatic memberSupported by Silverlight for Windows Phone Empty Gets a value that represents a static empty Size.
Public propertySupported by Silverlight for Windows Phone Height Gets or sets the height of this instance of Size.
Public propertySupported by Silverlight for Windows Phone IsEmpty Gets a value that indicates whether this instance of Size is Empty.
Public propertySupported by Silverlight for Windows Phone Width Gets or sets the width of this instance of Size.

Top

Methods

  Name Description
Public methodSupported by Silverlight for Windows Phone Equals(Object) Compares an object to an instance of Size for equality. (Overrides ValueType.Equals(Object).)
Public methodSupported by Silverlight for Windows Phone Equals(Size) Compares a value to an instance of Size for equality.
Protected methodSupported by Silverlight for Windows Phone Finalize Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by Silverlight for Windows Phone GetHashCode Gets the hash code for this instance of Size. (Overrides ValueType.GetHashCode().)
Public methodSupported by Silverlight for Windows Phone GetType Gets the Type of the current instance. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows Phone MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by Silverlight for Windows Phone ToString Returns a string representation of this Size. (Overrides ValueType.ToString().)

Top

Operators

  Name Description
Public operatorStatic memberSupported by Silverlight for Windows Phone Equality Compares two instances of Size for equality.
Public operatorStatic memberSupported by Silverlight for Windows Phone Inequality Compares two instances of Size for inequality.

Top

Remarks

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 Silverlight native code.

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

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 Silverlight. 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 Silverlight; 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 Silverlight.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Thread Safety

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

See Also

Reference