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. vue中样式的典型操作(:class,:style)

    <template> <div class="home-wrapper"> <div class="home-top">th ...

  2. 4步解决“Microsoft Office Professional Plus 2013在安装过程中出错”

    公司新搭建了AD域,公司内使用了1年多的电脑,现在要加入域,加域过程问题错综复杂. 其中一台电脑上,反应说Excel经常卡住,严重影响使用,所以考虑重装office2013.在控制面板卸载了: 卸载完 ...

  3. hive的常见判断与抽样函数

    .If函数:if和case差不多,都是处理单个列的查询结果 语法: if(boolean testCondition, T valueTrue, T valueFalseOrNull) 返回值: T ...

  4. node.js浅见

    看过很多朋友node.js代码敲得很好,但是对于概念还是很生疏.个人认为,代码是树叶,树干搭起来才是王道. 1.简述node.js的适用场景: IIO密集而非计算密集的情景:高并发微数据(比如账号系统 ...

  5. Java基础总结3

    计算只做加法计算 减法也是加法计算出来的: 1,顺序结构: 按照编写代码的顺序从上而下逐行翻译执行: 特点:每行代码都能被执行到且被执行一次: 2,选择结构看条件: 条件为true(成立)执行代码块: ...

  6. window 10 删除带有管理员权限的Oracle文件夹

    因为文件已经被删除就不附图解释了 因为文件安装的方式错误,所以本是按照正常步骤卸载Oracle,前面的禁用Orace服务与删除Oracle注册表都没有出错,但到最后一步---------Oracle文 ...

  7. Swift ios应用开发实践

  8. php 随机红包算法

    <?php /** * 红包分配算法 * * example * $coupon = new Coupon(200, 5); * $res = $coupon->handle(); * p ...

  9. MyTests

    目录 About Tests Selenium自动化测试 Pyppeteer Explain About Tests 扯淡!测试之瞎扯淡 Selenium自动化测试 什么是Selenium? Sele ...

  10. bzoj4710 [Jsoi2011]分特产(容斥)

    4710: [Jsoi2011]分特产 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 814  Solved: 527[Submit][Status] ...