UIElement.ClipToBounds 属性

定义

获取或设置一个值,该值指示是否剪切此元素的内容(或来自此元素的子元素的内容)使其适合包含元素的大小。Gets or sets a value indicating whether to clip the content of this element (or content coming from the child elements of this element) to fit into the size of the containing element. 这是依赖项属性。This is a dependency property.

public:
 property bool ClipToBounds { bool get(); void set(bool value); };
public bool ClipToBounds { get; set; }
member this.ClipToBounds : bool with get, set
Public Property ClipToBounds As Boolean

属性值

如果应剪切内容,则为 true;否则为 falsetrue if the content should be clipped; otherwise, false. 默认值为 falseThe default value is false.

注解

对于子元素,对于布局行为 ClipToBounds 具有不同的效果,具体取决于父元素的高度和宽度是否由 Height / WidthMaxHeight / MaxWidth确定。For child elements, ClipToBounds has different effects on layout behaviors depending on whether the height and width of the parent element are being determined by Height / Width or MaxHeight / MaxWidth. 无论 ClipToBounds 的值是什么,都将始终考虑父元素 MaxHeight / MaxWidth,并且有效的剪辑将始终根据这些最大值来剪裁内容。MaxHeight / MaxWidth of the parent element are always respected regardless of the value of ClipToBounds and the effective clipping will always clip the content based on these maximums. ClipToBounds false时,父级的 Height / Width 设置不会剪裁内容,但如果 ClipToBounds true,则会剪裁内容。The parent's Height / Width settings will not clip the content when ClipToBounds is false, but will clip the content if ClipToBounds is true.

请注意,默认为 false 是在 UIElement 类中实现的常规行为。Note that defaulting to false is the general behavior as implemented in the UIElement class. 派生自 UIElement 的任何给定元素都可以重写该实例中此属性的依赖项属性元数据,以默认改为 trueIt is possible for any given element that derives from UIElement to override the dependency property metadata for this property in that instance to default to true instead. 多个现有的派生类将重写此元数据和/或调整依赖属性的默认值。Several existing derived classes override this metadata and/or adjust the dependency property default value.

InkCanvasInkPresenterPopup 都将重写要 true的默认值。InkCanvas, InkPresenter, and Popup each override the default value to be true.

FrameworkElement 重写此依赖项属性的元数据。FrameworkElement overrides the metadata for this dependency property. 具体而言,FrameworkElement 指定此属性以允许属性值继承(Inherits 在元数据中 true)。Specifically, FrameworkElement designates this property to allow property value inheritance (Inherits is true in metadata). 此上下文中的属性值继承表示,如果有子元素没有通过本地值或样式分配的 ClipToBounds 的其他值,则为已分配此值的最近父元素的值(同样,在样式中,默认值为)或本地值),则由属性系统将父元素中的值分配给所有未分配的子元素。Property value inheritance in this context means that if there are child elements with no other value for ClipToBounds assigned through local values or styles, the value of the nearest parent element with this value assigned (again, either in styles, by default values, or a locally value), then the value from the parent element will be assigned to all unassigned child elements by the property system. 在实践中,这意味着您可以指定是否允许在根元素处使用剪辑到边界,并将该值传播到未专门分配给 false的所有子元素。In practice this means that you can specify whether to allow clip to bounds at the root element, and that value will propagate to all child elements that have not specifically assigned it as false.

依赖项属性信息Dependency Property Information

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

适用于

另请参阅