开发者

How can I anchor an ImageBrush to the bottom-left of an element?

开发者 https://www.devze.com 2023-02-21 23:09 出处:网络
I want to use an ImageBrush in a WPF element, and I want it to tile. But I want the image to line up with the bottom-left of the control, not the top-left. That is, instead of the top of the topmost t

I want to use an ImageBrush in a WPF element, and I want it to tile. But I want the image to line up with the bottom-left of the control, not the top-left. That is, instead of the top of the topmost tile being even with the top of the control, and a partial tile on the bottom end, I want it the other way around: the bottom of the bottom-most tile even with the bottom of the control, and a partial tile at the top. How can I do this?

Here's some XAML that repeats an image, but that anchors it to the control's top-left:

<Rectangle>
  <Rectangle.Fill>
    <ImageBrush ImageSource="C:\Temp\triangle.png"
                Viewport="0 0 31 31"
                ViewportUnits="Absolute"
                TileMode="Tile"/>
  </Rectangle.Fill>
</Rectangle>

Here's an illustration of what this does, and what I'm looking for (including what I want to happen as the element resizes):

How can I anchor an ImageBrush to the bottom-left of an element?

(source: excastle.com)

How can I anchor the tiled images to the bottom of the element instead of the top (and make sure they stay anchored at the bottom, even as the element resizes开发者_开发百科)?


The 'easiest' way is by calculating a other Viewport coordinates.

If the image is 20x20: Viewport="0 11 31 31" I could be wrong by a couple of units.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号