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. day24--面向对象基础

    要理解面向对象,我们首先要知道什么是面向过程 面向过程: 面向过程重点在过程两个字,神马是过程,这还要解释吗?我还是说下吧,过程就是一条线,一个步骤跟着一个步骤,更生动点的说就是像工厂里面的流水线一样 ...

  2. python之dict(或对象)与json之间的互相转化

    在Python语言中,json数据与dict字典以及对象之间的转化,是必不可少的操作. 在Python中自带json库.通过import json导入. 在json模块有2个方法, loads():将 ...

  3. vue单文件组件实例2:简单单文件组件

    ​ Introduce.vue: <template> <div class="intro"> 单位介绍 </div> </templat ...

  4. 遗传算法(Genetic Algorithm, GA)及MATLAB实现

    遗传算法概述: • 遗传算法(Genetic Algorithm,GA)是一种进化算法,其基本原理是仿效生物界中的“物竞天择.适者生存”的演化法则,它最初由美国Michigan大学的J. Hollan ...

  5. 新疆大学ACM-ICPC程序设计竞赛五月月赛(同步赛) H XOR

    链接:https://www.nowcoder.com/acm/contest/116/H来源:牛客网 题目描述 Once there was a king called XOR, he had a ...

  6. WebSocket 的理解

    WebSocket是HTML5开始提供的一种浏览器与服务器间进行全双工通讯的网络技术.依靠这种技术可以实现客户端和服务器端的长连接,双向实时通信. 它的最大特点就是,服务器可以主动向客户端推送信息,客 ...

  7. id、class等各种选择器总结

    1.  id              选择器       #     class        选择器        .     标签         选择器       标签名     群组   ...

  8. mysql批量导出单结构与结构数据表脚本

    由于一个库里面不需要导出全部, 只需要导出一部分指定的数据表结构与数据 那么就写了一个比较简单而且为了能偷懒的小shell #!/bin/bash #************************* ...

  9. 读Vue源码二 (响应式对象)

    vue在init的时候会执行observer方法,如果value是对象就直接返回,如果对象上没有定义过_ob_这个属性,就 new Observer实例 export function observe ...

  10. python经典程序

    输入输出 #判断输入整数是否在[0,100]之间 num = eval(input("请输入一个整数:")) if num > 100 or num < 0: #判断[ ...