federubin
federubin

Reputation: 636

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.

Upvotes: 10

Views: 11809

Answers (1)

James Close
James Close

Reputation: 932

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.

Upvotes: 11

Related Questions