WPF中的渐变画刷的一些案例
来源:互联网 发布:端口设置 编辑:程序博客网 时间:2024/06/16 20:49
WPF的渐变画刷,这些画刷改变不同DrawingBrush对象的几何图形,创建渐变为不同形状的平铺模式。
下面是来自一个国外的一些渐变画刷案例:
案例1:定义一个简单的直线,这个几何图形是基于DrawingBrush的扩展,当直线是垂直或水平时,这条线的宽度扩展25个单位。
案例源码:
<!-- ======================================================== AnimatedDrawingBrush1.xaml (c) 2006 by Charles Petzold ======================================================== --><Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Page.Background> <DrawingBrush TileMode="FlipXY" ViewportUnits="Absolute" Viewport="0 0 25 25"> <DrawingBrush.Drawing> <GeometryDrawing> <GeometryDrawing.Geometry> <PathGeometry Figures="M 0 0 L 25 0"> <PathGeometry.Transform> <RotateTransform x:Name="xform" /> </PathGeometry.Transform> </PathGeometry> </GeometryDrawing.Geometry> <GeometryDrawing.Pen> <Pen Brush="Black" Thickness="1" /> </GeometryDrawing.Pen> </GeometryDrawing> </DrawingBrush.Drawing> </DrawingBrush> </Page.Background> <Page.Triggers> <EventTrigger RoutedEvent="Page.Loaded"> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetName="xform" Storyboard.TargetProperty="Angle" From="0" To="360" Duration="0:0:10" RepeatBehavior="Forever" /> </Storyboard> </BeginStoryboard> </EventTrigger> </Page.Triggers></Page>
效果如下图:
渐变前效果:
渐变后效果:
案例2:定义一个嵌套的视图盒子,这个盒子是使用Viewbox,当盒子的角度改变时,通过会裁剪盒子,这时每个盒子会相邻的盒子融合
案例源码:
<!-- ======================================================== AnimatedDrawingBrush2.xaml (c) 2006 by Charles Petzold ======================================================== --><Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Page.Background> <DrawingBrush TileMode="FlipXY" ViewportUnits="Absolute" Viewport="0 0 30 30" ViewboxUnits="Absolute" Viewbox="-10 -10 20 20" > <DrawingBrush.Drawing> <GeometryDrawing> <GeometryDrawing.Geometry> <PathGeometry Figures="M 0 0 L 10 10 L -10 10 Z"> <PathGeometry.Transform> <RotateTransform x:Name="xform" /> </PathGeometry.Transform> </PathGeometry> </GeometryDrawing.Geometry> <GeometryDrawing.Pen> <Pen Brush="Black" Thickness="1" /> </GeometryDrawing.Pen> </GeometryDrawing> </DrawingBrush.Drawing> </DrawingBrush> </Page.Background> <Page.Triggers> <EventTrigger RoutedEvent="Page.Loaded"> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetName="xform" Storyboard.TargetProperty="Angle" From="0" To="360" Duration="0:0:10" RepeatBehavior="Forever" /> </Storyboard> </BeginStoryboard> </EventTrigger> </Page.Triggers></Page>
效果图如下:
渐变前的效果:
渐变后的效果:
案例3:定义了一个旋转的螺旋,旋转方向是逆时针
案例源码:
<!-- ======================================================== AnimatedDrawingBrush3.xaml (c) 2006 by Charles Petzold ======================================================== --><Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Page.Background> <DrawingBrush x:Name="brush" TileMode="Tile" ViewportUnits="Absolute" Viewport="0 0 20 20" ViewboxUnits="Absolute" Viewbox="-80 -80 160 160" > <DrawingBrush.Drawing> <GeometryDrawing> <GeometryDrawing.Geometry> <PathGeometry Figures="M 0 0 C 5 5, 5 5, 0 10 C -5 15, -15 10, -20 0 C -25 -10, -15 -25, 0 -30 C 15 -35, 35 -20, 40 0 C 45 20, 25 45, 0 50 C -25 55, -55 30, -60 0 C -65 -30, -35 -65, 0 -70 C 35 -75, 70 -40, 80 0"> <PathGeometry.Transform> <RotateTransform x:Name="xform" /> </PathGeometry.Transform> </PathGeometry> </GeometryDrawing.Geometry> <GeometryDrawing.Pen> <Pen Brush="Black" Thickness="5" /> </GeometryDrawing.Pen> </GeometryDrawing> </DrawingBrush.Drawing> </DrawingBrush> </Page.Background> <Page.Triggers> <EventTrigger RoutedEvent="Page.Loaded"> <BeginStoryboard> <Storyboard> <RectAnimation Storyboard.TargetName="brush" Storyboard.TargetProperty="Viewport" From="0 0 20 20" To="20 20 20 20" Duration="0:0:01" RepeatBehavior="Forever" /> <DoubleAnimation Storyboard.TargetName="xform" Storyboard.TargetProperty="Angle" From="0" To="-360" Duration="0:0:4" RepeatBehavior="Forever" /> </Storyboard> </BeginStoryboard> </EventTrigger> </Page.Triggers></Page>
效果图如下:
来源网址:http://www.charlespetzold.com/blog/2006/07/230620.html
0 0
- WPF中的渐变画刷的一些案例
- 自学WPF--第五课渐变画刷
- wpf 颜色渐变的圆
- 29.wpf程序设计指南[第二章]渐变画刷
- WPF中的画刷
- WPF中两条路径渐变的探讨
- WPF的一些资源
- wpf的一些
- WPF渐变背景
- WPF TreeView使用的简单案例
- 使用WPF+MVVM模式的小案例
- 关于css渐变的一些收集
- 一些非常好看的背景颜色渐变
- 关于WPF的一些书
- 关于WPF的一些东东
- WPF一些概念的区别
- WPF中的ChildWindow----WPF的toolkit使用
- WPF中的ChildWindow----WPF的toolkit使用
- windows、linux查看端口占用
- Ehcache 整合Spring 使用页面、对象缓存
- MVC伪一个12306图片验证码
- Ehcache详细解读
- Android苦手的App之旅(周边:XMind默认Style修改)
- WPF中的渐变画刷的一些案例
- Ubuntu16.04破解 MyEclipse
- set 和 multiset
- 树状数组—改点求段
- 一种红包发送功能的实现(redis+mysql+quartz)
- python 4-1-2 正则表达式一张图清晰归纳和实现细节
- csv文件生成及删除目录下的所有文件
- 在中软学习的第二天作业
- 删数问题