Window.SizeToContent 屬性

定義

取得或設定值,這個值表示視窗是否會自動隨內容調整本身大小。

public:
 property System::Windows::SizeToContent SizeToContent { System::Windows::SizeToContent get(); void set(System::Windows::SizeToContent value); };
public System.Windows.SizeToContent SizeToContent { get; set; }
member this.SizeToContent : System.Windows.SizeToContent with get, set
Public Property SizeToContent As SizeToContent

屬性值

SizeToContent 值。 預設為 Manual

範例

下列範例示範如何在程式碼中設定 SizeToContent 屬性,以指定視窗調整大小以符合其內容的方式。


// Manually alter window height and width
this.SizeToContent = SizeToContent.Manual;

// Automatically resize width relative to content
this.SizeToContent = SizeToContent.Width;

// Automatically resize height relative to content
this.SizeToContent = SizeToContent.Height;

// Automatically resize height and width relative to content
this.SizeToContent = SizeToContent.WidthAndHeight;

' Manually alter window height and width
Me.SizeToContent = SizeToContent.Manual

' Automatically resize width relative to content
Me.SizeToContent = SizeToContent.Width

' Automatically resize height relative to content
Me.SizeToContent = SizeToContent.Height

' Automatically resize height and width relative to content
Me.SizeToContent = SizeToContent.WidthAndHeight

備註

當 設定為 WidthAndHeightSizeToContent ,設定 HeightWidth 沒有作用;這兩個屬性都可以設定,但它們設定的值不會套用至視窗。

當 設定為 HeightSizeToContent ,設定 Height 不會變更視窗的高度。

當 設定為 WidthSizeToContent ,設定 Width 不會變更視窗的寬度。

如果 SizeToContent 具有 以外的 Manual 值:

  • SizeToContent 如果使用者使用調整大小底框或拖曳框線來調整視窗大小,就會自動設定 Manual 為 。

  • 如果內容的大小以導致視窗自行調整大小的方式變更, SizeChanged 則會引發 。

如果視窗為透明 (看到 AllowsTransparency) ,您應該考慮將 設定 SizeToContentWidthAndHeight ,以確保視窗不會大於其可見的內容。

注意

當視窗裝載在瀏覽器中時,您無法設定或取得這個屬性。

相依性屬性資訊

識別碼欄位 SizeToContentProperty
設定為 的中繼資料屬性 true

適用於

另請參閱