I want to create an area in my application that looks draggable. Usually, you see this done with a background of small dots or squares, or sometimes lines. I'm using Silverlight and I want to simply create a background that is a set of repeating small rectangles. I honestly cannot figure out how to generate a background with xaml. I'd rather not have to create every little rectangle -- this will also cause the control not to scale. Is there some way to repeat xaml elements to form a pattern? This would be similar to CSS repeating backgrounds, but I would like to use xaml instead of images.
+4
A:
You can use a brush, like this:
<Rectangle>
<Rectangle.Fill>
<LinearGradientBrush EndPoint="6,6" StartPoint="2,2" SpreadMethod="Repeat" MappingMode="Absolute">
<GradientStop Color="#FFAFAFAF" Offset="0"/>
<GradientStop Color="#00FFFFFF" Offset="1"/>
<GradientStop Color="#00FFFFFF" Offset="0.339"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
I've nicked this particular example from the excellent blacklight project, you'll need to play around with all the different settings to see what does what. I'm guessing a radial brush will allow you to get dots, etc. I think they created it in blend as all the numbers were crazy decimals until I sanitised them a bit.
mattmanser
2009-07-09 16:33:37
Thanks! I found the same snippet. I am wondering how to do it in 2 dimensions to get a rectangular pattern (like you said, radialBrush might help). But this gets me on the right track. It still would be interesting to have a xaml repeater of sorts. I guess I could just write my own layout control to do that.
Pete
2009-07-09 17:08:42
I think a repeater wouldn't be very good performance wise (e.g. a thousand elements in a listbox takes a second or two to render).
mattmanser
2009-07-10 09:25:53