原文: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. DSO Framer _ WinForm 使用

    根据自己对dsoframer控件的学习,想把dsoframer控件进行简单的包装为C#的usercontrol,大体需要作如下:(创建windows的usercontrol的步骤就不再说了...)我们 ...

  2. 【例题3-2 UVA - 10082】WERTYU

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 用一个字符数组,用数组的下标相邻来代表相邻的关系. [错的次数] 在这里输入错的次数 [反思] int i; for (i = 0; ...

  3. FreeMarker分页组件监听器

    分页组件监听器 /*  * project名:    * 包     名: com.companyName.dhm.iepgm.common.taglib  * 文 件名: PaginatedList ...

  4. ATL入门

    服务端代码----------------------------------------------------------------------------------------------- ...

  5. 我的前端规范——JavaScript篇

    相关文章 简书原文:https://www.jianshu.com/p/5918c283cdc3 我的前端规范——开篇:http://www.cnblogs.com/shcrk/p/9271561.h ...

  6. shell脚本if条件总结

    原文链接:https://geniuspeng.github.io/2018/03/12/shell-if/ shell编程中,if-then是一种常见的控制流命令,而if的条件判断一般采用内置命令t ...

  7. windows 空闲超时 非管理员如何破解

    windows 空闲超时 非管理员如何破解

  8. 【35.00%】【z13】&&【b093】最优贸易

    [题解] 这题就是要在n个点里面选一个花费最小的点.然后找一个花费最大的点.两者之差为最大值. 但是最大值的点要在最小值的点之后出现.且走到后者之后要能够到达N号节点.为了处理掉环.先用tarjan进 ...

  9. udp网络程序-发送、接收数据

    1. udp网络程序-发送数据 创建一个基于udp的网络程序流程很简单,具体步骤如下: 创建客户端套接字 发送/接收数据 关闭套接字 代码如下: #coding=utf-8from socket im ...

  10. ios 第一篇文章-xcode6.2键盘调不出来

    ios 第一篇文章 不晓得有没有人遇到过ios代码内调用键盘(keyboard)调不出来的情况,反正我是遇到了,按官方文档的说法调用键盘事件非常easy事实上: 我用了之后,不晓得为嘛,键盘就是不显示 ...