Search code examples
c#wpfimagebrush

Why is my ImageBrush scaling a Tiled image?


I have the following ImageBrush declaration that I want to use to draw the background of a window.

     <ImageBrush x:Key="Fondo" 
      ImageSource="Fondo.png"        
      Viewport="0,0,0.1,0.1" TileMode="Tile"/>

If I set it using a StaticResource binding to the Background property of the Window the brush is rendered correctly, but the image is being scaled. This is a behavior I don't want, I want the application to use the image at its native resolution and repeat it as necessary to fill the window background, without any kind of scaling. I don't know what I'm doing wrong.

The image I'm using is 200px wide and 200px tall. The viewport values I have there were guessed, but it was not working before I did that.

Thanks for any help

EDIT: Fixed a contradiction in the question


Solution

  • Found the problem. The image was a png that was designed for a 72 dpi resolution. Therefore WPF was scaling it to match the standard 96 dpi resolution. The problem was not with the code.