Window.SizeToContent 属性

定义

获取或设置一个值,该值指示窗口是否自动调整自身大小以适应其内容大小。Gets or sets a value that indicates whether a window will automatically size itself to fit the size of its content.

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

一个 SizeToContent 值。A SizeToContent value. 默认值为 ManualThe default is Manual.

示例

下面的示例演示如何 SizeToContent 在代码中设置属性,以指定如何调整窗口大小以适应其内容。The following example shows how to set the SizeToContent property in code to specify how a window resizes to fit its content.


// 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

注解

SizeToContent 设置为时 WidthAndHeight ,设置 HeightWidth 不起作用; 这两个属性都可以设置,但设置它们的值不会应用于窗口。When SizeToContent is set to WidthAndHeight, setting either Height or Width has no effect; both properties can be set, but the values they are set with are not applied to the window.

SizeToContent 设置为时 Height ,设置不 Height 会更改窗口的高度。When SizeToContent is set to Height, setting Height does not change the height of the window.

SizeToContent 设置为时 Width ,设置不 Width 会更改窗口的宽度。When SizeToContent is set to Width, setting Width does not change the width of the window.

如果的 SizeToContent 值不是 ManualIf SizeToContent has a value other than Manual:

  • SizeToContentManual如果用户使用重设大小手柄或拖动边框来调整窗口的大小,则将自动设置为。SizeToContent is automatically set to Manual if a user resizes the window by using the resize grip or dragging the border.

  • 如果内容大小以导致窗口大小调整的方式变化, SizeChanged 则会引发。If the size of the content changes in a way that causes the window to resize itself, SizeChanged is raised.

如果某个窗口是透明的 (参阅 AllowsTransparency) ,应考虑将设置 SizeToContent 为, WidthAndHeight 以确保该窗口不大于其可见内容。If a window is transparent (see AllowsTransparency), you should consider setting SizeToContent to WidthAndHeight to ensure the window is no larger than its visible content.

备注

当窗口承载于浏览器中时,不能设置或获取此属性。You cannot set or get this property when a window is hosted in a browser.

依赖项属性信息Dependency Property Information

标识符字段Identifier field SizeToContentProperty
元数据属性设置为 trueMetadata properties set to true None

适用于

另请参阅