形状与斜线作为背景

时间:2012-06-14 12:00:48

标签: c# .net wpf background shape

是否可以绘制具有斜线背景的Shape

Rectangle示例(抱歉图像质量):

enter image description here

如果我想要虚线或更改线条属性(笔触,粗细......)?

2 个答案:

答案 0 :(得分:2)

您可以使用本文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>

只需更改参数等以适合您的应用

用法:

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

答案 1 :(得分:0)