UIElement.Clip UIElement.Clip UIElement.Clip UIElement.Clip Property

定义

获取或设置用于定义元素内容轮廓的几何图形。Gets or sets the geometry used to define the outline of the contents of an element. 这是依赖项属性。This is a dependency property.

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

属性值

用于剪裁区域大小的几何图形。The geometry to be used for clipping area sizing. 默认值为 null GeometryThe default is a null Geometry.

示例

此示例演示如何定义框架元素的Clip区域。This example shows how to define a framework element's Clip region. 若要定义剪辑, 请使用Geometry (例如EllipseGeometry ) 来设置元素的Clip属性。To define a clip, use a Geometry (for example, an EllipseGeometry to set the element's Clip property. 只有位于几何区域内的区域才可见。Only the area that is within the region of the geometry will be visible.

下面的示例演示一个Image元素, 该元素没有定义的剪辑区域。The following example shows an Image element without a defined clip region. 由于未定义剪辑区域, 因此将显示整个图像。Because no clip region is defined, the entire image is displayed.

<Image Source="sampleImages\Waterlilies.jpg" 
  Width="200" Height="150" HorizontalAlignment="Left" />

应用剪辑区域之前的对象An object before applying a clip region
不包含剪辑区域的图像Image with No Clip Region

在下一个示例中, 将创建一个相同的映像, 只不过它具有定义的剪辑区域。In the next example, an identical Image is created, except that it has a defined clip region. 仅将显示区域中的EllipseGeometry图像部分。Only the part of the image that is within the area the EllipseGeometry will be displayed.

<Image 
  Source="sampleImages\Waterlilies.jpg" 
  Width="200" Height="150" HorizontalAlignment="Left">
  <Image.Clip>
    <EllipseGeometry
      RadiusX="100"
      RadiusY="75"
      Center="100,75"/>
  </Image.Clip>
</Image>

剪切的对象A clipped object
带有椭圆形剪辑区域的图像Image with an Elliptical Clip Region

下面的示例演示如何对框架元素的Clip区域进行动画处理。The following example shows how animate a framework element's Clip region. 在此示例中, EllipseGeometry用于定义Image元素的椭圆形剪辑区域。In this example, an EllipseGeometry is used to define an elliptical clip region for an Image element. PointAnimation 椭圆Center几何图形的属性从 (0, 0) 动画处理为 (200, 150)。A PointAnimation animates the ellipse geometry's Center property from (0, 0) to (200, 150). 动画加载并无限重复后, 动画就会开始播放。The animation starts playing after the image is loaded and repeats indefinitely.

<Image
  Source="sampleImages\Waterlilies.jpg" 
  Width="200" Height="150" HorizontalAlignment="Left">
  <Image.Clip>
    <EllipseGeometry x:Name="MyEllipseGeometry1"
      RadiusX="100"
      RadiusY="75"
      Center="100,75"/>
  </Image.Clip>
  <Image.Triggers>
    <EventTrigger RoutedEvent="Image.Loaded">
      <BeginStoryboard>
        <Storyboard>
          <PointAnimation 
            Storyboard.TargetName="MyEllipseGeometry1" 
            Storyboard.TargetProperty="(EllipseGeometry.Center)"
            From="0,0" To="200,150" Duration="0:0:3" RepeatBehavior="Forever" 
            AutoReverse="True" />
          </Storyboard>
      </BeginStoryboard>
    </EventTrigger>
  </Image.Triggers>
</Image> 

有关完整示例, 请参阅剪辑区域示例For the full sample, see the Clip Region Sample.

注解

在呈现的布局中, 将以可视方式裁剪几何图形外的元素。Elements outside the geometry will be visually clipped in the rendered layout. 几何图形不必是矩形。The geometry does not have to be rectangular.

依赖项属性信息Dependency Property Information

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

适用于

另请参阅