共用方式為


UIElement.Clip Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets or sets the Geometry used to define the outline of the contents of a UIElement.

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public Property Clip As Geometry
public Geometry Clip { get; set; }
<uiElement>
  <uiElement.Clip>
    singleGeometry
  </uiElement.Clip>
</uiElement>

XAML Values

Property Value

Type: System.Windows.Media.Geometry
The geometry to be used for clipping area sizing. The default value is nulla null reference (Nothing in Visual Basic).

Remarks

Dependency property identifier field: ClipProperty

A UIElement outside the geometry will be visually clipped in the rendered layout. The geometry does not have to be rectangular.

The clipped area is the "outside" of the geometry. In other words, the content that is shown (not clipped) is the area of the geometry that would otherwise have a Fill if the geometry were used as data for a Path rather than for clipping. The clipped area is any area that falls outside the geometry overlay. For complex geometries, the areas that are clipped or not clipped are influenced by the geometry's FillRule.

Clipping by using just LineGeometry causes total clipping because the line by itself has no dimension. EllipseGeometry, GeometryGroup, or RectangleGeometry is probably the simplest to use; however, you can use a PathGeometry for more complex results.

You can specify a complex geometry for Clip if you specify a single GeometryGroup as the value and populate the group with child geometries

An alternative approach for showing only part of a UIElement visually is to use OpacityMask, using either a RadialGradientBrush or an ImageBrush that uses a transparency mask. If you use the OpacityMask technique, you can create "bleed" effects against the background. The Clip technique always results in hard edges where the clip is applied.

For example code, see How to: Crop an Object.

Examples

For a XAML example, see How to: Crop an Object.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.