Do not scale ImageBrush when resizing, repeat it!

I have a problem with ImageBrush :

 <Window ... > <Grid> <Grid.Background> <ImageBrush ImageSource="Controls\Images\notebook_paper_Line.jpg" TileMode="FlipX" Viewport="0,0,1,0.09" /> </Grid.Background> </Grid> </Window> 

I want to repeat the image while resizing the user window. But currently, the image is scaled when the user resizes the window. (Note that the image size is small, and I use TileMode and Viewport to repeat it, and the problem occurs when resizing!).

Any XAML code will be great! :)

and I'm sorry about bad english !!!

+6
c # resize wpf scale
source share
1 answer

By default, the Viewport for TileBrush is 0,0,1,1, and ViewportUnits is RelativeToBoundingBox, which means that 0,0,1,1 displays the entire size of the destination (in this case, the borders of the grid).

So, if you want to focus ImageBrush, you will need to configure Viewport. If you must set Viewport to 0,0, .5, .5, you should see 2 x 2 tiles (since each tile will be 50% x50% of the grid size) or 0,0,0,25, 0.1 will produce 4x10 tiles, etc.

However, this still does not prevent image scaling. Thus, in your case, what you probably want is to set the viewport size to the size of your image and set ViewportUnits to Absolute instead of RelativeToBoundingBox.

In xaml below, I have a 24x24 pixel image, so I set my viewport accordingly. This will fragment the image again for the full size of the grid. If the grid is changed, more fragments will appear.

 <ImageBrush ImageSource="Images\book_green.png" TileMode="FlipX" Viewport="0,0,24,24" ViewportUnits="Absolute" /> 

I hope this helps.

+13
source share

All Articles