当前位置:网站首页>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 合并两个图形
边栏推荐
- Babbitt | Metaverse daily must-read: Weibo animation will recruit all kinds of virtual idols around the world and provide support for them...
- ACP-Cloud Computing By Wakin自用笔记(1)云计算基础、虚拟化技术
- 如何进行自动化测试?
- 实验室专利书写指南
- GBase8s存储过程
- Usage of collect_list in Scala105-Spark.sql
- curl命令的那些事
- vantui 组件 van-field 路由切换时,字体样式混乱问题
- 关于使用腾讯云HiFlow场景连接器每天提醒签到打卡
- 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
猜你喜欢

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

ACP-Cloud Computing By Wakin自用笔记(1)云计算基础、虚拟化技术

基于 eBPF 的 Kubernetes 可观测实践

Those things about the curl command

EasyCVR如何通过接口调用设备录像的倍速回放?

部署LVS-DR群集

方法的重写

工业元宇宙对工业带来的改变

How does the intelligent video surveillance platform EasyCVR use the interface to export iframe addresses in batches?

Flink/Scala - Storing data with RedisSink
随机推荐
2019年海淀区青少年程序设计挑战活动小学组复赛试题详细答案
通配符SSL证书不支持多域名吗?
Matlab drawing 1
win10 uwp 动态修改ListView元素布局
Route lazy loading
Kubernetes入门到精通- Operator 模式入门
自己经常使用的三种调试:Pycharm、Vscode、pdb调试
DHCP&OSPF combined experimental demonstration (Huawei routing and switching equipment configuration)
The Industrial Metaverse Brings Changes to Industry
如何进行自动化测试?
智能视频监控平台EasyCVR如何使用接口批量导出iframe地址?
情绪的波动起伏
ros2订阅esp32发布的电池电压数据
ptables基本语法使用规则
How does EasyCVR call the double-speed playback of device recording through the interface?
使用.NET简单实现一个Redis的高性能克隆版(二)
Scala104 - Built-in datetime functions for Spark.sql
[Distributed Advanced] Let's fill in those pits in Redis distributed locks.
LVS负载均衡群集之原理叙述
数据库SqlServer迁移PostgreSql实践