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 效果的更多相关文章

  1. CSS3中的动画效果记录

    今天要记录的是CSS3中的三种属性transform.transition以及animation,这三个属性大大提升了css处理动画的能力. 一.Transform 变形 CSS中transform ...

  2. CSS3中box-shadow的用法介绍

    一般我们通过box-shadow来设置盒阴影,但是有些属性我们一般没有用到,这篇文章将对box-shadow属性进行逐个分析.语法 CSS Code复制内容到剪贴板 E {box-shadow:ins ...

  3. CSS3 中的按钮效果与进度条

    效果如图

  4. css3中的动画效果

    css3中的animation属性动画效果代码如下: <!DOCTYPE html> <html lang="en"> <head> <m ...

  5. CSS3中的动画效果-------Day72

    还记得么,在前面也曾实现过"仅仅用css让div动起来",还记得当时是怎么实现的么,是的,transition,针对的也比較局限,仅仅有旋转角度啊,长宽啊之类的,所以说,与其说是动 ...

  6. 【移动端debug-1】css3中box-shadow的溢出问题

    今天做项目遇到一个box-shadow的溢出父容器的问题,如下面的代码中,子容器inner的box-shadow在没有任何设置的情况下是溢出父容器的. 代码: <!DOCTYPE html> ...

  7. css3新增属性有哪些?css3中常用的新增属性总结

    css3新增属性有哪些?来提问这个问题的人都应该知道css3是css的升级版本,那么,css3既然是升级版本,自然是会新增一些属性,接下来本篇文章将给大家介绍关于css3中常用的新增属性. 一.css ...

  8. css3中的动画功能

    直接用我的一段代码演示下css3中实现动画效果的事例,让一个div自动旋转起来 代码如下: <!doctype html> <html lang="en"> ...

  9. 来看看css3中的box-shadow

    不谈IE,只谈谈box-shadow的具体使用方法 语法: E {box-shadow: <length> <length> <length>?<length ...

随机推荐

  1. mongols的反向代理和负载均衡功能

    mongols是C++ 服务器基础设施库,它最近更新提供了反向代理和负载均衡功能. 以下为用mongols代理两个nodejs后端(8888和8889)并与nginx压测对比图: 压测显示mongol ...

  2. Centos7 安装tomcat

  3. Recycle----项目总结

    github项目地址:https://github.com/HuChengLing/recycle 软件规模: 我们这个Recycle app属于一个小型项目,整体规模不大.预期有垃圾回收和二手品交易 ...

  4. java中存储mysql数据库时间类型

    Mysql 与 java 的时间类型 MySql的时间类型有 Java中与之对应的时间类型   date                 java.sql.Date   Datetime        ...

  5. 解决mysql连接报“Communications link failure”错误

    <!--定义在从数据库获取新连接失败后重复尝试的次数.默认值: 30 :小于等于0表示无限次--> <property name="acquireRetryAttempts ...

  6. linux使用vim打开乱码问题

    在windows中编辑好的汉字文本文档,上传到Linux下打开乱码. [root@localhost ~]# rpm -ivh /mnt/Packages/lrzsz-0.12.20-36.el7.x ...

  7. gzip对字符串的压缩和解压

    package org.jc.plugins.gzip; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStre ...

  8. 进行分支切换时,出现error的修复方法

    进行分支切换时,出现如此错误,导致无法正常切换:error: The following untracked working tree files would be overwritten by ch ...

  9. kali-通过获取路由器pin码套取无线网络密码shell脚本

    直接上脚本吧, 我做个笔记. #************************************************************************* # > Fil ...

  10. Matlab 将两个图像进行分离 已知其中一个图像

    5.下图(a)是一幅两个灰度图像合成的图像,已知其中一幅图像如图(b)所示,试把另一幅图像提取出来,并显示. 运用减法做 %加载入要处理的图片 A=imread('a.png'); %将I变为[0,1 ...