1

I've got a 64x64 image that I'm using as the source of a VisaulBrush which I tile over the background of a control. However, based on some run-time logic, I want to change the origin of the visual brush. Not the tile size, just where the 'upper left' if you will is. In other words, think of it not as an offset into the tile itself, but rather an offset on where on the control the tiling begins.

However, asides from faking it by using the original image to manually render into a second image of the same size using a 2x2 pattern that starts at a specific negative offset (thus clipping that 2x2 to the size of the tile), then using that image as the source for the actual tile brush, not sure how else I can achieve this. I'm surprised I haven't just seen any sort of TileOffset or something similar. May end up rolling my own subclass of the brush that does exactly that.

Unless someone else knows an easier way to do this... :)

Mark A. Donohoe
  • 28,442
  • 25
  • 137
  • 286

1 Answers1

3

well as it states here TileBrushs Viewport Property:

Gets or sets the position and dimensions of the base tile for a TileBrush

you can easily adjust the first two parameters of the ViewPort to offset the tile. eg:

<ImageBrush ImageSource="..."
  Viewport="0,0,20,20" ViewportUnits="Absolute"
  TileMode="Tile" />

if that was your base and you want to offset this 5px in x direction you do:

<ImageBrush ImageSource="..."
  Viewport="5,0,20,20" ViewportUnits="Absolute"
  TileMode="Tile" />

As TileBrush is a base for ImageBrush just as for VisualBrush this applies equally to VisualBrush.

Markus Hütter
  • 7,796
  • 1
  • 36
  • 63
  • I'll have to try this. I thought that doing a 5,0,20,20 like that made you end up with a 'tile that was actually 15x20 and not 20x20 which is what I want. But I'll check this out. If it works, I'll mark yours as accepted. – Mark A. Donohoe Mar 31 '11 at 00:32
  • Yep! That was it. I misunderstood what those coordinates did. I was thinking it was more mapping, but it's not... it's positioning. You've been voted up and accepted. :) – Mark A. Donohoe Mar 31 '11 at 01:05