最近在用WPF制作一款软件,需要像ps一样表示透明区域,于是制作了一个马赛克背景的style。实现比较简单,那么过程和思路就不表了,直接上代码
<DrawingBrush TileMode="Tile" Stretch="Uniform" ViewportUnits="Absolute" Viewport="0,0,16,16">
<DrawingBrush.Drawing>
<DrawingGroup>
<DrawingGroup.Children>
<GeometryDrawing Brush="White">
<GeometryDrawing.Geometry>
<RectangleGeometry Rect="0,0,10,10"/>
</GeometryDrawing.Geometry>
</GeometryDrawing>
<GeometryDrawing Brush="#FFBFBFBF">
<GeometryDrawing.Geometry>
<RectangleGeometry Rect="0,0,5,5"/>
</GeometryDrawing.Geometry>
</GeometryDrawing>
<GeometryDrawing Brush="#FFBFBFBF">
<GeometryDrawing.Geometry>
<RectangleGeometry Rect="5,5,5,5"/>
</GeometryDrawing.Geometry>
</GeometryDrawing>
</DrawingGroup.Children>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
效果:
如果有其他实现方法和思路欢迎交流