如何将 ImageBrush 锚定到元素的左下角?
我想在 WPF 元素中使用 ImageBrush,并且希望它平铺。但我希望图像与控件的左下角对齐,而不是与左上角对齐。也就是说,我不想让最顶部图块的顶部与控件的顶部齐平,并且部分图块位于底端,而是相反:最底部图块的底部与控件的底部齐平。控件和顶部的部分图块。我该怎么做?
下面是一些重复图像的 XAML,但将其锚定到控件的左上角:
<Rectangle>
<Rectangle.Fill>
<ImageBrush ImageSource="C:\Temp\triangle.png"
Viewport="0 0 31 31"
ViewportUnits="Absolute"
TileMode="Tile"/>
</Rectangle.Fill>
</Rectangle>
这是其作用以及我正在寻找的内容的说明(包括元素调整大小时我希望发生的情况):
(来源:excastle.com)
我如何锚定将平铺图像放置到元素的底部而不是顶部(并确保它们保持锚定在底部,即使元素调整大小也是如此)?
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):
(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)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“最简单”的方法是计算其他视口坐标。
如果图像是 20x20: Viewport="0 11 31 31" 我可能会错几个单位。
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.