WPF - 如何制作绘制方格纸状正方形的画笔?

WPF - How can I make a brush that paints graph-paper-like squares?(WPF - 如何制作绘制方格纸状正方形的画笔?)
本文介绍了WPF - 如何制作绘制方格纸状正方形的画笔?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建一个画笔来绘制一个规则的、重复的网格,该网格由 1 个单位的粗线在水平轴和垂直轴上均匀分布?想象一下方格纸,如果你愿意的话.

How might I create a brush that paints a regular, repeated grid of 1-unit thick lines spaced evenly in both the horizontal and vertical axes? Imagine graph paper, if you will.

理想情况下,该解决方案将允许控制用于线条和背景(正方形内的区域)的画笔.通过这种方式,背景可以是透明的,这样网格就可以用作叠加层.

Ideally the solution would allow control over the brushes used for the lines and the background (the regions within the squares). In this way the background could be transparent, so that the grid could serve as an overlay.

编辑下面这张图显示了 Tom 的回答结果:

EDIT Here is an image that shows the result of Tom's answer below:

在本例中,使用网格来合成三层以显示网格是真正透明的.

For this example a grid was used to composite three layers to show that the grid is truly transparent.

推荐答案

来自 http://msdn.microsoft.com/en-us/library/aa480159.aspx

<DrawingBrush Viewport="0,0,10,10" 
              ViewportUnits="Absolute"
              TileMode="Tile">
  <DrawingBrush.Drawing>
    <DrawingGroup>
      <GeometryDrawing Geometry="M0,0 L1,0 1,0.1, 0,0.1Z" Brush="Green" />
      <GeometryDrawing Geometry="M0,0 L0,1 0.1,1, 0.1,0Z" Brush="Green" />
    </DrawingGroup>
  </DrawingBrush.Drawing>
</DrawingBrush>

这篇关于WPF - 如何制作绘制方格纸状正方形的画笔?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
quot;Overflowquot; compiler error with -9223372036854775808L(编译器错误-9223372036854775808L(Q;溢出Q))
Visual Studio 2010 ReportViewer Assembly References(Visual Studio 2010 ReportViewer程序集引用)
Weird behaviour when I open a reportviewer in WPF(在WPF中打开报表查看器时出现奇怪的行为)
how do i pass parameters to aspnet reportviewer(如何将参数传递给aspnet report查看器)