Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF: How do I create a background that repeats horizontally without scaling?

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.

like image 624
federubin Avatar asked Nov 23 '09 12:11

federubin


1 Answers

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:

<ImageBrush ImageSource="Images/my-background-image.png" 
            TileMode="FlipY" 
            Stretch="Uniform"
            AlignmentY="Top"
            Viewport="0,0,90,3000"
            ViewportUnits="Absolute" />

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.

like image 160
James Close Avatar answered Oct 17 '22 12:10

James Close