WPF Window Background ImageBrush not tiling

后端 未结 2 514
轻奢々
轻奢々 2021-02-18 23:12

I have a window with a background image. The image may change at runtime which really should not matter for this.

I want the image to be fixed to the top left (which it

2条回答
  •  旧巷少年郎
    2021-02-19 00:00

    If you would like the entire solution in c#

    ImageBrush brush = new ImageBrush();
    brush.ImageSource = new BitmapImage(new Uri(@"c:\your\image\source.gif"));
    brush.TileMode = TileMode.Tile;
    brush.ViewportUnits = BrushMappingMode.Absolute;
    brush.Viewport = new Rect(0, 0, brush.ImageSource.Width, brush.ImageSource.Height);
    
    MainWindow1.Background = brush;
    

提交回复
热议问题