原文:WPF 用Clip属性实现蒙板特效

上一篇,已简单介绍Clip属性的用法,这一篇用它来实现简单蒙板功能,很简单,直接上代码

<Window x:Class="擦除效果.MainWindow"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        Title="MainWindow" Height="537" Width="866" MouseMove="canvas_MouseMove" MouseDown="Window_MouseDown" MouseUp="Window_MouseUp">

    <Grid>

        <Rectangle Height="100" HorizontalAlignment="Left" Margin="164,92,0,0" Name="rectangle1" Stroke="Black" VerticalAlignment="Top" Width="200" Fill="Lime" />

        <Button Content="Button" Height="83" HorizontalAlignment="Left" Margin="526,109,0,0" Name="button1" VerticalAlignment="Top" Width="115" Click="button1_Click" />

        <Grid x:Name="grid"  Background="#88FFFFFF" ></Grid>

    </Grid>

    <Window.Background>

        <ImageBrush ImageSource="/擦除效果;component/Images/s01.jpg" />

    </Window.Background>

</Window>

后台:

    public partial class MainWindow : Window

    {

        private bool isDown = false;

        public MainWindow()

        {

            InitializeComponent();

            RectangleGeometry rg = new RectangleGeometry();

            rg.Rect = new Rect(0, 0, this.Width, this.Height);

            gridGeometry = Geometry.Combine(gridGeometry, rg, GeometryCombineMode.Union, null);

            grid.Clip = gridGeometry;

        }

        PathGeometry gridGeometry = new PathGeometry();

        private void canvas_MouseMove(object sender, MouseEventArgs e)

        {

            if (isDown)

            {

                EllipseGeometry rg = new EllipseGeometry();

                rg.Center = e.GetPosition(this);

                rg.RadiusX = 50;

                rg.RadiusY = 50;

                //排除几何图形

                gridGeometry = Geometry.Combine(gridGeometry, rg, GeometryCombineMode.Exclude, null);

                grid.Clip = gridGeometry;

            }

        }

        private void button1_Click(object sender, RoutedEventArgs e)

        {

            MessageBox.Show("OK!");

        }

        private void Window_MouseDown(object sender, MouseButtonEventArgs e)

        {

            isDown = true;

        }

        private void Window_MouseUp(object sender, MouseButtonEventArgs e)

        {

            isDown = false;

        }

    }

效果如下:

源码

WPF 用Clip属性实现蒙板特效的更多相关文章

  1. SVG 2D入门9 - 蒙板

    SVG支持的蒙板 SVG支持多种蒙板特效,使用这些特性,我们可以做出很多很炫的效果.至于中文中把mask叫做"蒙板"还是"遮罩"就不去区分了,这里都叫做蒙板吧. ...

  2. CLIP PATH (MASK) GENERATOR是一款在线制作生成clip-path路径的工具,可以直接生成SVG代码以及配合Mask制作蒙板。

    CLIP PATH (MASK) GENERATOR是一款在线制作生成clip-path路径的工具,可以直接生成SVG代码以及配合Mask制作蒙板. CLIP PATH (MASK) GENERATO ...

  3. WPF通过不透明蒙板切割显示子控件

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/Backspace110/article/ ...

  4. WPF 元素裁剪 Clip 属性

    本文介绍如何在 WPF 使用 Clip 裁剪元素 在 WPF 的 UIElement 提供了 Clip 属性,这个属性默认是空,但是如果设置了这个属性就会对元素进行裁剪 这个属性是一个 Geometr ...

  5. WPF弹出带蒙板的消息框

    效果图 思路 拿到父级窗体的内容,放入一个容器里,再在容器里放入一个半透明层.将整个容器赋给父级窗体的内容. 关闭时反向操作. 代码 消息窗弹出时 /// <summary> /// 弹出 ...

  6. WPF蒙板弹窗

    由于界面设计需要,要给弹窗添加蒙板效果,在百度和google搜索了半天,竟然没有一个满意的方案,最后只能自己想办法实现了一个,原理还是比较简单的,现在分享给大家. 先看一下效果..      原理其实 ...

  7. NeHe OpenGL教程 第二十课:蒙板

    转自[翻译]NeHe OpenGL 教程 前言 声明,此 NeHe OpenGL教程系列文章由51博客yarin翻译(2010-08-19),本博客为转载并稍加整理与修改.对NeHe的OpenGL管线 ...

  8. 利用 js 实现弹出蒙板(model)功能

    关于 js 实现一个简单的蒙板功能(model) 思路: 创建一个蒙板, 设置蒙板的堆叠顺序保证能将其它元素盖住 position: absolute; top: 0; left: 0; displa ...

  9. ListView鼠标框选实现蓝色蒙板

    此问题留心已久,今日方悉心求之,记录心得. ListView控件,不论Delphi中的TListView还是c#中的ListView,在开启其MultiSelect属性时,鼠标框选只是显示框张,如下图 ...

随机推荐

  1. 随手可得的Application对象

    在Android的开发其中,Application和Context对象应该是我们接触最多的对象了,特别是Context对象. 当我们在某个Activity或者Service其中时,因为它们本身就是Co ...

  2. [CSS] Design for Mobile First with Tachyons

    Tachyons provides extensions (-ns, -m, and -l) to many of its classes to help you design for respons ...

  3. css3-7 如何让页面元素水平垂直都居中(元素定位要用css定位属性)

    css3-7 如何让页面元素水平垂直都居中(元素定位要用css定位属性) 一.总结 一句话总结:元素定位要用css定位属性,而且一般脱离文档流更加好操作.先设置为绝对定位,上左都50%,然后margi ...

  4. Ubuntu10.04下安装Qt4和创建第一个Qt程序

    1.首先安装Qt4并采用Qt Creator进行开发演示 (1)在Terminal中输入: sudo apt-get install qt4-dev-tools qt4-doc qt4-qtconfi ...

  5. 访问sharepoint站点自动使用当前用户名和密码登录

    https://blog.csdn.net/zw_2011/article/details/7417123 1.把sharepoint站点添入可信站点.   点击菜单栏“工具”——〉“Internet ...

  6. mysql中的触发器和事务的操作

    触发器 语法 创建触发器: CREATE TRIGGER trigger_name trigger_time trigger_event ON tbl_name FOR EACH ROW trigge ...

  7. Mysql 安装(Using Generic Binaries)

    本次 Mysql 为Community 5.6.21 版本号.安装方式为通用Linux安装方式.即大多数Linux平台都能够採用该方式进行安装. 一.安装步骤 1.安装环境 1)Centos 7.0. ...

  8. hreadPoolExecutor使用和思考(上)-线程池大小设置与BlockingQueue的三种实现区别

    阅读更多 工作中多处接触到了ThreadPoolExecutor.趁着现在还算空,学习总结一下. 前记: jdk官方文档(javadoc)是学习的最好,最权威的参考. 文章分上中下.上篇中主要介绍Th ...

  9. 【codeforces 758C】Unfair Poll

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

  10. linux 安装scrt

    http://www.vandyke.com/products/securecrt/  wget http://download.boll.me/securecrt_linux_crack.pl pe ...