原文:WPF 关于圆角的制作

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

设置CornerRadius属性

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

...

</Border>

2、创建ClippingBorder类:

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 {
/// <Remarks>
/// As a side effect ClippingBorder will surpress any databinding or animation of
/// its childs UIElement.Clip property until the child is removed from ClippingBorder
/// </Remarks>
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="你的命名空间"

<control:ClippingBorder CornerRadius="20">
<StackPanel Background="Yellow">
<Label>Hello World</Label>
</StackPanel>
</control:ClippingBorder>

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

<Border Width="300" Height="100">
<Border.Clip>
<PathGeometry>
<PathGeometry.Figures>
<PathFigure StartPoint="0,0" IsClosed="True">
<LineSegment Point="300,0" />
<LineSegment Point="300,80" />
<ArcSegment Point="280,100" Size="20,20" SweepDirection="Clockwise"/>
<LineSegment Point="0,100" />
</PathFigure>
</PathGeometry.Figures>
</PathGeometry>
</Border.Clip>
<StackPanel Background="Yellow">
<Label>Hello World</Label>
</StackPanel>
</Border>

WPF 关于圆角的制作的更多相关文章

  1. [原译]WPF绘制圆角多边形

    原文:[原译]WPF绘制圆角多边形 介绍 最近,我发现我需要个圆角多边形.而且是需要在运行时从用户界面来绘制.WPF有多边形.但是不支持圆角.我搜索了一下.也没找到可行的现成例子.于是就自己做吧.本文 ...

  2. WPF如何用TreeView制作好友列表、播放列表

    WPF如何用TreeView制作好友列表.播放列表 前言 TreeView这个控件对于我来说是用得比较多的,以前做的小聊天软件(好友列表).音乐播放器(播放列表).类库展示器(树形类结构)等都用的是T ...

  3. WPF如何用TreeView制作好友列表、播放列表(转)

    WPF如何用TreeView制作好友列表.播放列表 前言 TreeView这个控件对于我来说是用得比较多的,以前做的小聊天软件(好友列表).音乐播放器(播放列表).类库展示器(树形类结构)等都用的是T ...

  4. WPF textbox 圆角制作

    在app.xaml中加入以下节点,全局设置textbox圆角 <Style TargetType="{x:Type TextBox}">            < ...

  5. WPF button 圆角制作

    将以下节点复制到app.xaml的<Application.Resources>节点下 <Style TargetType="{x:Type Button}"&g ...

  6. WPF passwordbox 圆角制作

    将以下节点复制到app.xaml的<Application.Resources>节点下 <Style TargetType="PasswordBox">   ...

  7. WPF combobox 圆角制作

    修改ComboBox的Template, 在VS 2010或者Blend中你可以导出ComboBox的默认模板: VS2010中: 然后修改里面的模板,比如: <Window x:Class=& ...

  8. 【WPF】Bitmap Effect制作圆角加渲染TextBox

    <Window.Resources> <ControlTemplate x:Key="txtTemplate" TargetType="{x:Type ...

  9. 使用WPF为Powershell程序制作GUI界面

    1. 使用Xaml创建应用界面 打开visual studio,创建一个新的项目,在已安装模板中选择Visual C# →Wpf应用. 完成创建后,我们得到如下图所示的应用界面. wpf界面是基于xa ...

随机推荐

  1. Android系统开发(8)——linx进程基本概念

    一.proc文件系统 传统意义上的文件系统是用于块设备上信息的存储,/proc这个目录是一个虚拟文件系统,它放置的数据都是在内存当中,所以这个目录本身不占用任何硬盘空间.主要包含如下系统信息: 内存管 ...

  2. chrome-extensions -- copytables. verygood

    https://www.crx4chrome.com/extensions/ekdpkppgmlalfkphpibadldikjimijon/,通过设置快捷键,一般是拷贝多行

  3. 一起学libcef--给你的浏览器删除cookie

    long long ago, 我们讨论了如给你cef设置cookie. 如今来补充一点,假设给你的浏览器删除某一cookie. review一下设置cookie: std::wstring usern ...

  4. Uploadify404无效链接

    Uploadify404无效链接 在使用Jquery Uploadify插件的時候.会发如今请求中有个返回值为404的请求. 假如如今的location为www.aa.com/bugs/more. h ...

  5. ios开发零散知识点总结

    1:当有导航栏的时候,子视图为UIScrollView,或是继承于UIScrollView的控件如UITableView,UICollectionView等,控制器会自动调用 self.automat ...

  6. Lucene学习总结之六:Lucene打分公式的数学推导 2014-06-25 14:20 384人阅读 评论(0) 收藏

    在进行Lucene的搜索过程解析之前,有必要单独的一张把Lucene score公式的推导,各部分的意义阐述一下.因为Lucene的搜索过程,很重要的一个步骤就是逐步的计算各部分的分数. Lucene ...

  7. php array数组的相关处理函数and str字符串处理与正则表达式

    下面给各位同学整理了一些关于php array数组的相关处理函数and str字符串处理与正则表达式,希望文章对你会有所帮助.   数组的相关处理函数: 1)数组的键值操作函数 array_value ...

  8. Theano Multi Layer Perceptron 多层感知机

    理论 机器学习技法:https://www.coursera.org/course/ntumltwo 假设上述网址不可用的话,自行度娘找别人做好的种子.或者看这篇讲义也能够:http://www.cn ...

  9. 利用PS把多张psd格式的图片转换为一张PDF格式

    最近为公司做了一版电子样册,所有图片都是包含多图层高清晰的psd格式,要做成一个PDF文件的电子样册,发给客户看,面对这些零散的图片,本来打算利用在线合成:在线网址 https://smallpdf. ...

  10. JAVA基本数据类型及其转换

    Java语言是一种强类型语言.这意味着每个变量都必须有一个声明好的类型.Java语言提供了八种基本类型.六种数字类型(四个整数型,两个浮点型),一种字符类型,还有一种布尔型.Java另外还提供大数字对 ...