WPF:如何创建水平重复而不缩放的背景?
我想为我的窗口创建一个背景,这是我想要水平重复的图像。到目前为止,我已尝试使用 ImageBrush,但此选项会水平和垂直重复图像。另外,我不希望它在用户调整窗口大小时缩放,因为这会使图像看起来很有趣。
I would like to create a background for my window which is an image that I want repeated horizontally. So far I've tried with the ImageBrush, but this option repeats the image horizontally and vertically. Also, I don't want it to scale when user resize the window, as it makes the image look funny.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想要做的是水平平铺图像,就像在 CSS 中一样,使用简单的一行“background-repeat:repeat-x”,那么经过一些(!)尝试和错误后,您需要什么XAML 是这样的:
其中 Viewport 属性的最后 2 个值是图像的宽度(以像素为单位),然后是一个高于视口高度的非常大的数字,以便图像在该高度内的 Y 方向上不会重复。
If what you want to do is tile an image horizontally as you would in CSS with the simple one liner "background-repeat: repeat-x" then after some (!) trial and error what you need in XAML is this:
Where the last 2 values on the Viewport attribute are the width of your image in pixels and then a very large number that is higher than your viewport height so that the image is not repeated in the Y direction within that height.