ImageBrush
我试过这样做,但在将其设置为网格的背景之前,我无法弄清楚如何设置它的高度和宽度。
BitmapImage bmp= new BitmapImage(new Uri(imagePath, UriKind.Relative));
int height = bmp.DecodePixelHeight;
int width = bmp.DecodePixelWidth;
ImageBrush imgBrush = new ImageBrush();
imgBrush.ImageSource = bmp;
MainGrid.Background = imgBrush // MainGrid is the name of the Grid