I am trying to create one rectangle filled with Horizontal or Vertical lines. The width of the rectangle is dynamic so I can not use an image brush. Please let me know if anybody knows any solution.
Correct me if I am wrong, are you suggesting that I should use an ImageDrawing and DrawingBrush TileMode set to "Tile" ?
Pravin
2010-05-20 15:44:44
Set Stretch to Fill otherwise nothing will work since it will always use the image default size.
Julien Lebosquain
2010-05-20 18:31:02
A:
ImageBrush
derives from TileBrush
so you can use the Viewport
property to repeat the image. See this MSDN page for an example.
Julien Lebosquain
2010-05-20 15:15:54
I am not able to visualize how this will work, the basic TileMode itself is not working for me here is a code snippet...<Rectangle.Fill> <ImageBrush ImageSource="C:\Pravin\DrawRectangleWithLines\horizontalLine.JPG" Stretch="None" TileMode="Tile" /> </Rectangle.Fill>
Pravin
2010-05-20 16:01:08
+1
A:
You can easily do this with a LinearGradientBrush:
<Rectangle Width="100" Height="100">
<Rectangle.Fill>
<LinearGradientBrush SpreadMethod="Reflect" StartPoint="0 0" EndPoint="0 0.05">
<GradientStop Offset="0.5" Color="Black"/>
<GradientStop Offset="0.5" Color="White"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
You control line thickness and orientation with the EndPoint property.
bitbonk
2010-05-23 00:37:41
A:
I figured out a straight-forward way of doing this; finally, I used following visual brush resources to fill rectangle with horizontal, vertical or dotted vertical lines respectively
<!--for horizontal lines-->
<VisualBrush
x:Key="HorizontalLines"
TileMode="Tile" Viewport="0,0,4,4"
ViewportUnits="Absolute" Viewbox="0,0,10,10"
ViewboxUnits="Absolute">
<VisualBrush.Visual>
<Canvas>
<Path Stroke="Black" Data="M 0 10 l 10 0" />
</Canvas>
</VisualBrush.Visual>
</VisualBrush>
<!--For vertical lines-->
<VisualBrush
x:Key="VerticalLines"
TileMode="Tile" Viewport="0,0,4,4"
ViewportUnits="Absolute" Viewbox="0,0,10,10"
ViewboxUnits="Absolute">
<VisualBrush.Visual>
<Canvas >
<Path Stroke="Black" Data="M 0 0 l 0 10" />
</Canvas>
</VisualBrush.Visual>
</VisualBrush>
<!--For dotted vertical lines-->
<VisualBrush
x:Key="DottedVerticalLinesWithFill"
TileMode="Tile" Viewport="0,0,10,10"
ViewportUnits="Absolute" Viewbox="0,0,10,10"
ViewboxUnits="Absolute">
<VisualBrush.Visual>
<Canvas>
<Path Stroke="Purple" Data="M 0 5l 0 -10" />
</Canvas>
</VisualBrush.Visual>
</VisualBrush>
Pravin
2010-06-10 19:46:26