博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
WPF 关于圆角的制作
阅读量:7114 次
发布时间:2019-06-28

本文共 2595 字,大约阅读时间需要 8 分钟。

原文:

1、使用Boder(一般情况):

设置CornerRadius属性

 <Border x:Name="border" CornerRadius="20">

...

</Border>

 

2、创建ClippingBorder类:

View Code
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Windows.Controls;using System.Windows.Media;using System.Windows; namespace Shgbit.Controls {    /// 
/// As a side effect ClippingBorder will surpress any databinding or animation of /// its childs UIElement.Clip property until the child is removed from ClippingBorder ///
public class ClippingBorder : Border { protected override void OnRender(DrawingContext dc) { OnApplyChildClip(); base.OnRender(dc); } public override UIElement Child { get { return base.Child; } set { if (this.Child != value) { if (this.Child != null) { // Restore original clipping this.Child.SetValue(UIElement.ClipProperty, _oldClip); } if (value != null) { _oldClip = value.ReadLocalValue(UIElement.ClipProperty); } else { // If we dont set it to null we could leak a Geometry object _oldClip = null; } base.Child = value; } } } protected virtual void OnApplyChildClip() { UIElement child = this.Child; if (child != null) { _clipRect.RadiusX = _clipRect.RadiusY = Math.Max(0.0, this.CornerRadius.TopLeft - (this.BorderThickness.Left * 0.5)); Rect rect = new Rect(this.RenderSize); rect.Height -= (this.BorderThickness.Top + this.BorderThickness.Bottom); rect.Width -= (this.BorderThickness.Left + this.BorderThickness.Right); _clipRect.Rect = rect; child.Clip = _clipRect; } } public void Update() { OnApplyChildClip(); } private RectangleGeometry _clipRect = new RectangleGeometry(); private object _oldClip; }}

用法:

需应用xmlns:control="你的命名空间"

 

3、使用Clip(通过路径):

 

转载地址:http://toghl.baihongyu.com/

你可能感兴趣的文章
c++构造函数详解
查看>>
ContentValues类和 Hashtable比较
查看>>
Php对python模块的调用
查看>>
composer 安装
查看>>
org.apache.spark.streaming.dstream.MappedDStream@5a69b104 has not been initialized
查看>>
linux shell 中判断字符串为空的正确方法
查看>>
致敬Linux系统
查看>>
DevSecOps 运维模式中的安全性
查看>>
Android 动画效果(一)
查看>>
node pm2 错误 配置
查看>>
UML---数据建模(Data Model Diagram)
查看>>
keystone 命令简要说明
查看>>
关于页面中锚跳转问题
查看>>
uboot/tools/mkimage工具详解
查看>>
编辑器中灯光菜单及其子菜单的使用介绍
查看>>
CocosStudio细节
查看>>
mysql General error: 1267 Illegal mix of collations错误
查看>>
maven, ant,ivy配置
查看>>
android sdk 下载地址 备忘
查看>>
LESS CSS 的简单使用
查看>>