原文: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. Textillate.js有什么用及使用实例

    Textillate.js有什么用及使用实例 一.总结 一句话总结:Textillate.js – 实现动感的 CSS3 文本动画的简单插件 二.textillate.js 文字动画 textilla ...

  2. [Angular] Configurable NgModules

    You probably have seen 'foorRoot()' method a lot inside Angular application. Creating a configurable ...

  3. [Webpack] Configure Prepack with Webpack

    Great improvements and optimizations can be made to the output of bundled code. Prepack provides the ...

  4. 驱动程序调试方法之printk——自制proc文件(一)

    首先我们需要弄清楚proc机制,来看看fs/proc/proc_misc.c这个文件,从入口函数开始看: proc_misc_init(void)         #ifdef CONFIG_PRIN ...

  5. GLPI-开源资产管理软件

    https://github.com/glpi-project/glpi/releases/tag/9.2.3 http://glpi-project.org/downloads/ 开源资产管理软件- ...

  6. thinkphp5多级控制器是什么?怎么使用?

    thinkphp5多级控制器是什么?怎么使用? 一.总结 1.多级控制器是让控制器的级数变成多级,也就是controller目录下可以新建其它目录. 2.使用的话注意目录下的控制的的命名空间(加上目录 ...

  7. SEO那些事:一句代码一键分享网站

    这是很久以前就已经写过的笔记了,有一个习惯,每次遇到一个问题,都会进行百度,然后把解决问题的关键点记录下来,有人问我,为什么更新频率如此之快,大部分都是从前积累的知识点. 其实每天工作所涉及的知识点都 ...

  8. Python 数组[],元组(),字典{}的异同

    序列 Python有6中内建的序列,在这里我们重点讨论两种,数组和元组.所有序列都可以做某些特定的操作,大致上常用的是:加,乘,索引,分片以及检查某个元素是否属于序列的成员. Python还提供一些内 ...

  9. [Angular] Using the platform agnostic Renderer & ElementRef

    ElementRef: ElementRef is a way to access native html element, notice that it only works for Broswer ...

  10. Erlang 位串和二进制数据

    http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=25876834&id=3300393 因为在本人工作中,服务端Erla ...