当前位置:网站首页>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 合并两个图形
边栏推荐
- vantui 组件 van-field 路由切换时,字体样式混乱问题
- GBase8s存储过程
- 2022 May 1 Mathematical Modeling Question C Explanation
- Thrift installation configuration
- After EasyCVR is locally connected to the national standard device to map the public network, the local device cannot play and cascade the solution
- 用Excel绘制统计图
- 路由懒加载
- 当项目中自动格式化插件Prettier和ESLint冲突报错时如何解决
- Flask框架实现注册加密功能详解【Flask企业课学习】
- 基于激励的需求响应计划下弹性微电网的短期可靠性和经济性评估(Matlab代码实现)
猜你喜欢

After EasyCVR is locally connected to the national standard device to map the public network, the local device cannot play and cascade the solution

企业即时通讯软件有哪些功能?对企业有什么帮助?

【软件工程之美 - 专栏笔记】37 | 遇到线上故障,你和高手的差距在哪里?

2019年海淀区青少年程序设计挑战活动小学组复赛试题详细答案

群友求助,一周没有搞定的需求,3分钟就解决了?

YOLOv7-Pose尝鲜,基于YOLOv7的关键点模型测评

BigDecimal 使用注意!!“别踩坑”

EuROC dataset format and related codes

DHCP&OSPF combined experimental demonstration (Huawei routing and switching equipment configuration)

CAN光纤转换器CAN光端机解决消防火灾报警
随机推荐
【软件工程之美 - 专栏笔记】37 | 遇到线上故障,你和高手的差距在哪里?
如何进行自动化测试?
GBase8s存储过程
【简答题】月薪4k和月薪8k的区别就在这里
当前最快的实例分割模型:YOLACT 和 YOLACT++
Flink / Scala - 使用 RedisSink 存储数据
Homework 8.3 Thread Synchronization Mutex Condition Variables
如何让 JS 代码不可断点
EasyCVR调用云端录像API接口返回错误且无录像文件生成,是什么原因?
开发那些事儿:如何通过EasyCVR平台获取监控现场的人流量统计数据?
八一建军节 | 致敬中国人民解放军
动态数组底层是如何实现的
July 31, 2022 Summary of the third week of summer vacation
测试/开发程序员男都秃头?女都满脸痘痘?过好我们“短暂“的一生......
HCIP-R&S By Wakin自用笔记(1)企业网络高级解决方案
vantui 组件 van-field 路由切换时,字体样式混乱问题
数据集成:holo数据同步至redis。redis必须是集群模式?
VPC2187/8 电流模式 PWM 控制器 4-100VIN 超宽压启动、高度集成电源控制芯片推荐
数仓相关,总结
测试工程师如何突破职业瓶颈?