原文: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. [Angular] Creating an Observable Store with Rx

    The API for the store is really simple: /* set(name: string, state: any); select<T>(name: stri ...

  2. Canvas基础知识总结之中的一个

    canvas的HTML语法: <canvas> Canvas not supported </canvas> 上面这句代码中内容部分所含的文本,这种文本的叫法"后备内 ...

  3. NoSql中的B-tree、B+tree和LSM-tree 分类: B7_HBASE 2015-03-15 18:27 85人阅读 评论(0) 收藏

    总结: 1.B+树将数据完全排序,读数据时很快,但当要修改数据时,就需要将新入数据下面的数据重新排位,特别是当写入的数据排在较高的位置时,需要大量的移位操作才能完成写入. 2.SLM牺牲部分的读性能, ...

  4. (十二)RabbitMQ消息队列-性能测试

    原文:(十二)RabbitMQ消息队列-性能测试 硬件配置 宿主机用的联想3850X6的服务器四颗E7-4850v3的处理器,DDR4内存,两块1.25TB的pcie固态.在宿主机上使用的事esxi5 ...

  5. 【35.29%】【codeforces 557C】Arthur and Table

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. java连接MongoDB查询导出为excel表格

    背景 因为项目需求.每一个星期须要统计每一个公众号7天的訪问数,月底就须要统计一个月的訪问数,40多个公众号.每次手动统计都须要花费1个小时,总之是一项无技术耗时耗神的手工活. 于是.想写个程序来统计 ...

  7. php实现栈的压入、弹出序列(**)(算法步骤)(画图)

    php实现栈的压入.弹出序列(**)(算法步骤)(画图) 一.总结 1.算法步骤:一定要把算法步骤写下来,要不然太浪费时间了,尤其是思维不清晰的时候,尤其是题目有难度的时候,不然的话也非常容易出现低级 ...

  8. 记录一次mysql由5.6升级到5.7出现的异常---Expression #23 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'c.commentCount' which is not functionally dependent on columns in GROUP BY clause;

    ### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Expre ...

  9. 《从零開始学Swift》学习笔记(Day 71)——Swift与C/C++混合编程之数据类型映射

    原创文章.欢迎转载.转载请注明:关东升的博客 posted @ 2017-07-21 13:23 zhchoutai 阅读(...) 评论(...) 编辑 收藏

  10. android webview中的音乐的暂停与播放

    前段时间有这样一个需求,webview显示一个带音乐的网页,在播放音乐的时候进入第三方软件暂停播放,返回时继续播放.后来参考了两篇文章解决了这个问题. AudioManager audioManage ...