当前位置:网站首页>WPF 元素裁剪 Clip 属性
WPF 元素裁剪 Clip 属性
2022-08-04 18:38:00 【林德熙】
本文介绍如何在 WPF 使用 Clip 裁剪元素
在 WPF 的 UIElement 提供了 Clip 属性,这个属性默认是空,但是如果设置了这个属性就会对元素进行裁剪
这个属性是一个 Geometry 属性,设置的值表示裁剪之后剩下的部分,如写一个简单的类继承 UIElement 然后对他进行裁剪
class SisdecereYipuVayderyecallMawqere : UIElement
{
/// <inheritdoc />
public SisdecereYipuVayderyecallMawqere()
{
}
/// <inheritdoc />
protected override void OnRender(DrawingContext drawingContext)
{
drawingContext.DrawRectangle(Brushes.Black,null,new Rect(10,10,100,100));
}
}现在这个类会在 10,10 的坐标画出大小是 100 的矩形
对他裁剪,设置裁剪的是矩形裁剪
public SisdecereYipuVayderyecallMawqere()
{
Clip = new RectangleGeometry(new Rect(30, 30, 50, 50));
}从图片很难看出来不同,只是可以看到两个矩形,第一个矩形比较大
对他进行圆形裁剪
public SisdecereYipuVayderyecallMawqere()
{
Clip = new EllipseGeometry(new Point(30, 30), 10, 10);
}可以看到显示的是圆形
因为设置 Clip 属性是一个裁剪的窗口,只有在裁剪区域之内才可以显示
因为 Geometry 是可以做到不连续的,所以可以做出部分的透明,如裁剪两个矩形
public SisdecereYipuVayderyecallMawqere()
{
Geometry geometry = new RectangleGeometry(new Rect(10,10,10,10));
geometry = Geometry.Combine(geometry, new RectangleGeometry(new Rect(30, 30, 10, 10)),
GeometryCombineMode.Union, null);
Clip = geometry;
}上面代码使用 Geometry.Combine 合并两个图形
边栏推荐
猜你喜欢

(ECCV-2022)GaitEdge:超越普通的端到端步态识别,提高实用性

PHP代码审计9—代码执行漏洞

Day018 继承

CIFAR发布《AI伦理的文化:研讨会报告》【附下载】

CPU突然飙高系统反应慢,是怎么导致的?有什么办法排查?

Documentary on Security Reinforcement of Network Range Monitoring System (1)—SSL/TLS Encrypted Transmission of Log Data

HCIA-R&S自用笔记(22)STP状态与计时器、STP拓扑变化、STP配置及实验

关于使用腾讯云HiFlow场景连接器每天提醒签到打卡

巴比特 | 元宇宙每日必读:微博动漫将招募全球各类虚拟偶像并为其提供扶持...

Develop those things: How to obtain the traffic statistics of the monitoring site through the EasyCVR platform?
随机推荐
测试/开发程序员男都秃头?女都满脸痘痘?过好我们“短暂“的一生......
mq消息积压怎么对应
margin 塌陷和重合的理解
How does the intelligent video surveillance platform EasyCVR use the interface to export iframe addresses in batches?
不论你是大众,科班和非科班,我这边整理很久,总结出的学习路线,还不快卷起来
Activity数据库字段说明
EuROC 数据集格式及相关代码
Thrift installation configuration
PHP代码审计9—代码执行漏洞
VPC2187/8 电流模式 PWM 控制器 4-100VIN 超宽压启动、高度集成电源控制芯片推荐
The Industrial Metaverse Brings Changes to Industry
ptables基本语法使用规则
Regardless of whether you are a public, professional or non-major class, I have been sorting out the learning route for a long time here, and the learning route I have summarized is not yet rolled up
【RTOS训练营】关于上课和答疑
ECCV 2022 | FPN错位对齐,实现高效半监督目标检测(PseCo)
链表的经典入门LeetCode题目
HCIA-R&S自用笔记(22)STP状态与计时器、STP拓扑变化、STP配置及实验
方法的重写
Short-term reliability and economic evaluation of resilient microgrids under incentive-based demand response programs (Matlab code implementation)
”元宇宙“必须具备这些特点