wpf 实现 css3 中 boxshadow inset 效果
using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes; public class BoxShadow {
public static Grid Create(Size size, Rect inner, GradientStopCollection sc) {
Func<PointCollection> ps = () => new PointCollection(Enumerable.Range(, ).Select(i => new Point()));
var left = new Polygon();
left.Points = ps();
left.Points[] = inner.TopLeft;
left.Points[] = inner.BottomLeft;
left.Points[] = new Point(, size.Height);
left.Fill = new LinearGradientBrush(sc, new Point(, ), new Point(, ));
var top = new Polygon();
top.Points = ps();
top.Points[] = new Point(size.Width, );
top.Points[] = inner.TopRight;
top.Points[] = inner.TopLeft;
top.Points[] = new Point(size.Width, );
top.Fill = new LinearGradientBrush(sc, new Point(, ), new Point(, ));
var right = new Polygon();
right.Points = ps();
right.Points[] = new Point(size.Width, size.Height);
right.Points[] = inner.BottomRight;
right.Points[] = inner.TopRight;
right.Points[] = new Point(size.Width, );
right.Points[] = new Point(size.Width, size.Height);
right.Fill = new LinearGradientBrush(sc, new Point(, ), new Point(, ));
var btm = new Polygon();
btm.Points = ps();
btm.Points[] = new Point(, size.Height);
btm.Points[] = inner.BottomLeft;
btm.Points[] = inner.BottomRight;
btm.Points[] = new Point(size.Width, size.Height);
btm.Points[] = new Point(, size.Height);
btm.Fill = new LinearGradientBrush(sc, new Point(, ), new Point(, )); var box = new Grid { Width = size.Width, Height = size.Height };
box.Children.Add(left);
box.Children.Add(top);
box.Children.Add(right);
box.Children.Add(btm);
return box;
}
}

var sc = new GradientStopCollection();
foreach (var item in new Dictionary<double, Color> { { , white }, { ., black }, { ., white }, { ., black }, { ., white } }) {
sc.Add(new GradientStop { Offset = item.Key, Color = item.Value });
}
var box = BoxShadow.Create(new Size(, ), new Rect(, , , ), sc);
for (var i = ; i < ; i++) {
movingBlock.Children.Add(new Grid {
Width = movingBlock.Width / ,
Height = movingBlock.Width / ,
Background = new VisualBrush { Visual = box }
});
//调一调颜色和 box 的 Rotate,就会出现小星星!
wpf 实现 css3 中 boxshadow inset 效果的更多相关文章
- CSS3中的动画效果记录
今天要记录的是CSS3中的三种属性transform.transition以及animation,这三个属性大大提升了css处理动画的能力. 一.Transform 变形 CSS中transform ...
- CSS3中box-shadow的用法介绍
一般我们通过box-shadow来设置盒阴影,但是有些属性我们一般没有用到,这篇文章将对box-shadow属性进行逐个分析.语法 CSS Code复制内容到剪贴板 E {box-shadow:ins ...
- CSS3 中的按钮效果与进度条
效果如图
- css3中的动画效果
css3中的animation属性动画效果代码如下: <!DOCTYPE html> <html lang="en"> <head> <m ...
- CSS3中的动画效果-------Day72
还记得么,在前面也曾实现过"仅仅用css让div动起来",还记得当时是怎么实现的么,是的,transition,针对的也比較局限,仅仅有旋转角度啊,长宽啊之类的,所以说,与其说是动 ...
- 【移动端debug-1】css3中box-shadow的溢出问题
今天做项目遇到一个box-shadow的溢出父容器的问题,如下面的代码中,子容器inner的box-shadow在没有任何设置的情况下是溢出父容器的. 代码: <!DOCTYPE html> ...
- css3新增属性有哪些?css3中常用的新增属性总结
css3新增属性有哪些?来提问这个问题的人都应该知道css3是css的升级版本,那么,css3既然是升级版本,自然是会新增一些属性,接下来本篇文章将给大家介绍关于css3中常用的新增属性. 一.css ...
- css3中的动画功能
直接用我的一段代码演示下css3中实现动画效果的事例,让一个div自动旋转起来 代码如下: <!doctype html> <html lang="en"> ...
- 来看看css3中的box-shadow
不谈IE,只谈谈box-shadow的具体使用方法 语法: E {box-shadow: <length> <length> <length>?<length ...
随机推荐
- Vue系列之 => html-webpack-plugin的两个基本作用
安装 npm i html-webpack-plugin -D webpack.config.js const path = require('path'); //启用热更新的第二步,导入webpac ...
- Ant构建原理及build.xml文档描述
最近在改写jmeter,用到ant构建,记录一下. Ant的概念Make命令是一个项目管理工具,而Ant所实现功能与此类似.像make,gnumake和nmake这些编译工具都有一定的缺陷,但是Ant ...
- 在.NET Core使用TimeZone将客户端时间转服务器本地时间但编译提示已过期
当我们的项目国际化后,需要处理时区问题. 在.NET Core之前我们可以通过以下代码将客户端时间转换为服务端时间: DateTime serverTime = TimeZone.CurrentTim ...
- CentOS与Win7远程桌面互通
在CentOS上装上Rdesktop即可连接Windows,如下命令,第一次执行时报错,提示CredSSP required by server. [root@localhost ~]# rdeskt ...
- PHP环境配置遇到的小问题
1.设置时区 2.默认打开文件 3.文件夹权限设置
- Linux下复制文件
命令: cp -Rf /文件名1/* /文件名2 把文件夹1下的文件复制到文件2中(/* 表示复制文件夹1下的文件,不复制文件夹1)
- HBase API 基础操作
对于数据操作,HBase支持四类主要的数据操作,分别是: Put :增加一行,修改一行 Delete :删除一行,删除指定列族,删除指定column的多个版本,删除指定column的制定版本等 Get ...
- mongodb常用查询语句
1.查询所有记录db.userInfo.find();相当于:select* from userInfo; 2.查询去掉后的当前聚集集合中的某列的重复数据db.userInfo.distinct(&q ...
- Spring Boot 2 整合Swagger简单入门
Swagger是一款RESTFUL接口的文档在线自动生成+功能测试功能软件. 1.pom.xml添加配置 可以到http://mvnrepository.com上搜索springfox,便可以看到Sp ...
- C# Finalize和Dispose的区别
一:总结 1.Finalize方法(C#中是析构函数,以下称析构函数)是用于释放非托管资源的,而托管资源会由GC自动回收.所以,我们也可以这样来区分 托管和非托管资源.所有会由GC自动回收的资源,就是 ...