語言

Size 結構

定義

實作 結構,用來描述物件的 Size。

public value class Size : IFormattable
[System.ComponentModel.TypeConverter(typeof(System.Windows.SizeConverter))]
[System.Serializable]
public struct Size : IFormattable
[System.ComponentModel.TypeConverter(typeof(System.Windows.SizeConverter))]
public struct Size : IFormattable
[<System.ComponentModel.TypeConverter(typeof(System.Windows.SizeConverter))>]
[<System.Serializable>]
type Size = struct
    interface IFormattable
[<System.ComponentModel.TypeConverter(typeof(System.Windows.SizeConverter))>]
type Size = struct
    interface IFormattable
Public Structure Size
Implements IFormattable
繼承
屬性
實作

範例

以下範例示範如何在程式碼中使用結構 Size 。

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 ;
}
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 ;
}
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

備註

Size 特別有用,因為它同時描述 Height 了物件的 和 Width 。 Size 在佈局系統中廣泛使用來排列和測量元素。

XAML 屬性使用方式

<object property="width,height"/>

XAML 值

寬度一個大於或等於0的值,指定結構的 。WidthSize

高度一個大於或等於0的值,指定結構的 。HeightSize

建構函式

名稱 Description
Size(Double, Double)

初始化結構的新實例 Size ,並賦予其初始 width 值與 height。

屬性

名稱 Description
Empty

得到一個代表靜態空值 Size的值。

Height

取得或設定 Height 的 Size。

IsEmpty

獲得一個值,表示該實例 Size 是否為 Empty。

Width

取得或設定 Width 的 Size。

方法

名稱 Description
Equals(Object)

將物件與 的 Size 實例比較以求相等。

Equals(Size, Size)

比較兩個 的 Size 實例,為相等。

Equals(Size)

將一個值與一個 Size 實例比較,以表示相等。

GetHashCode()

取得此實例 Size的雜湊碼。

Parse(String)

從轉換後Size的 回傳 的String實例。

ToString()

回傳代表此String物件的 aSize。

ToString(IFormatProvider)

回傳 a String 代表此實例 Size。

運算子

名稱 Description
Equality(Size, Size)

比較兩個 的 Size 實例,為相等。

Explicit(Size to Point)

明確地將 的 Size 一個實例轉換成 的 Point實例。

Explicit(Size to Vector)

明確地將 的 Size 一個實例轉換成 的 Vector實例。

Inequality(Size, Size)

比較兩個不平等的 Size 案例。

明確介面實作

名稱 Description
IFormattable.ToString(String, IFormatProvider)

此類型或成員支援 Windows Presentation Foundation(WPF)基礎架構,並非直接從您的程式碼中使用。

適用於

另請參閱