Shape with slanted lines as background

六月ゝ 毕业季﹏ 提交于 2021-01-27 11:38:21

问题


Is possible to draw a Shape that has a background made by slanted lines?

An example with Rectangle (sorry for the image quality):

enter image description here

And if i want dashed lines or change the line properties (stroke, thickness..)?


回答1:


You can use solution from this article http://mark-dot-net.blogspot.com/2007/06/creating-hatched-patterned-brush-in-wpf.html

<VisualBrush
  x:Key="HatchBrush"
  TileMode="Tile" Viewport="0,0,10,10"
  ViewportUnits="Absolute" Viewbox="0,0,10,10"   
  ViewboxUnits="Absolute">
  <VisualBrush.Visual>
    <Canvas>
       <Rectangle Fill="Azure" Width="10" Height="10" />
       <Path Stroke="Purple" Data="M 0 0 l 10 10" />
    </Canvas>
  </VisualBrush.Visual>
</VisualBrush>

Just change the parameters etc. to fit your application

Usage:

<Rectangle Width="80" Height="40"
    Fill="{StaticResource HatchBrush}"/>



回答2:


Does this help: [WPF, C#: Draw a line onto existing bitmap in image control] or http://msdn.microsoft.com/en-us/library/ms747393.aspx



来源:https://stackoverflow.com/questions/11032617/shape-with-slanted-lines-as-background

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!