Size Structure (System.Windows)

Switch View :
ScriptFree
.NET Framework Class Library
Size Structure

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Implements a structure that is used to describe the Size of an object.

Namespace:  System.Windows
Assembly:  WindowsBase (in WindowsBase.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
Syntax

Visual Basic
<SerializableAttribute> _
<TypeConverterAttribute(GetType(SizeConverter))> _
Public Structure Size _
	Implements IFormattable
C#
[SerializableAttribute]
[TypeConverterAttribute(typeof(SizeConverter))]
public struct Size : IFormattable
Visual C++
[SerializableAttribute]
[TypeConverterAttribute(typeof(SizeConverter))]
public value class Size : IFormattable
F#
[<Sealed>]
[<SerializableAttribute>]
[<TypeConverterAttribute(typeof(SizeConverter))>]
type Size =  
    struct
        interface IFormattable
    end
XAML Object Element Usage
<Size .../>
XAML Attribute Usage
<object property="width,height"/>

XAML Values

width

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

height

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

The Size type exposes the following members.

Constructors

  Name Description
Public method Size Initializes a new instance of the Size structure and assigns it an initial width and height.
Top
Properties

  Name Description
Public property Static member Empty Gets a value that represents a static empty Size.
Public property Height Gets or sets the Height of this instance of Size.
Public property IsEmpty Gets a value that indicates whether this instance of Size is Empty.
Public property Width Gets or sets the Width of this instance of Size.
Top
Methods

  Name Description
Public method Equals(Object) Compares an object to an instance of Size for equality. (Overrides ValueType.Equals(Object).)
Public method Equals(Size) Compares a value to an instance of Size for equality.
Public method Static member Equals(Size, Size) Compares two instances of Size for equality.
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Gets the hash code for this instance of Size. (Overrides ValueType.GetHashCode().)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method Static member Parse Returns an instance of Size from a converted String.
Public method ToString() Returns a String that represents this Size object. (Overrides ValueType.ToString().)
Public method ToString(IFormatProvider) Returns a String that represents this instance of Size.
Top
Operators

  Name Description
Public operator Static member Equality Compares two instances of Size for equality.
Public operator Static member Explicit(Size to Vector) Explicitly converts an instance of Size to an instance of Vector.
Public operator Static member Explicit(Size to Point) Explicitly converts an instance of Size to an instance of Point.
Public operator Static member Inequality Compares two instances of Size for inequality.
Top
Explicit Interface Implementations

  Name Description
Explicit interface implemetation Private method IFormattable.ToString This type or member supports the Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code.
Top
Remarks

Size is particularly useful because it describes both the Height and Width of an object. Size is used extensively by the layout system to arrange and measure elements.

Examples

The following example demonstrates how to use a Size structure in code.

Visual Basic

Protected Overrides Function MeasureOverride(ByVal availableSize As System.Windows.Size) As System.Windows.Size
    Dim panelDesiredSize As Size = New Size()
    ' In our example, we just have one child. 
    ' Report that our panel requires just the size of its only child.
    For Each child As UIElement In InternalChildren
        child.Measure(availableSize)
        panelDesiredSize = child.DesiredSize
    Next
    Return panelDesiredSize
End Function


C#

protected override Size MeasureOverride(Size availableSize)
{
    Size panelDesiredSize = new Size();

    // In our example, we just have one child. 
    // Report that our panel requires just the size of its only child.
    foreach (UIElement child in InternalChildren)
    {
        child.Measure(availableSize);
        panelDesiredSize = child.DesiredSize;
    }

    return panelDesiredSize ;
}


Visual C++

         virtual Size MeasureOverride(Size availableSize) override
         {
             Size^ panelDesiredSize = gcnew Size();

             // In our example, we just have one child. 
             // Report that our panel requires just the size of its only child.
             for each (UIElement^ child in InternalChildren)
             {
                 child->Measure(availableSize);
				 panelDesiredSize = child->DesiredSize;
             }
             return *panelDesiredSize ;
         }


More Code

How to: Create an Elliptical Arc This example shows how to draw an elliptical arc. To create an elliptical arc, use the PathGeometry, PathFigure, and ArcSegment classes.
Version Information

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Platforms

Windows 8 Consumer Preview, Windows Server 8 Beta, Windows 7, Windows Server 2008 SP2, Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

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