我有一个包含Canvas控件的WPF用户控件,并且在该控件上我想要平铺与控件高度相同但不宽的图像。我已成功使用此代码:
ImageBrush brush = new ImageBrush();
brush.ImageSource = new BitmapImage(new Uri(System.AppDomain.CurrentDomain.BaseDirectory + "\\res\\01.PNG"));
brush.TileMode = TileMode.Tile;
brush.ViewportUnits = BrushMappingMode.Absolute;
brush.Viewport = new Rect(0, 0, brush.ImageSource.Width, brush.ImageSource.Height);
brush.Stretch = Stretch.None;
bkgCanvas.Background = brush;
但是,当我运行此图像时,图像会进行少量缩放,因此它会比实际尺寸大。我需要它以实际尺寸显示而不进行缩放。