Question

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

Was it helpful?

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.

OTHER TIPS

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" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top