tags:

views:

843

answers:

2

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

+2  A: 

If you know the resolution of the source image, you can set the ViewBox and ViewPort values as pixels. Set ViewBoxUnits and ViewPortUnits to absolute and you should be able to achieve the effect that you want.

<ImageBrush ViewBox="0,0,200,200" 
ViewBoxUnits="Absolute"
ViewPort="0,0,200,200"
ViewPortUnits="Absolute" />
Alex
doesn't work. The image is still being stretched... Thanks nevertheless
Kiranu
A: 

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.

Kiranu
How did you fix it?
PRINCESS FLUFF
I fixed it changing the resolution of the image. I was creating the image in Adobe Fireworks under a resolution of 72 dpi. The problem was that WPF works with a 96 dpi resolution, so the image was being automatically scaled. If you are suffering the same issue, modify the image for 96 dpi, or if possible, use a vectorized one
Kiranu