我试过这样做,但在将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发布于 2013-10-15 11:41:00
如果您只想将imageBrush设置为正确填充网格,请将imageBrush的stretch属性设置为uniform (保持比例,但可能会留下空白斑点)或uniform to fill (保持比例,不留下空白斑点,但整个图片可能不适合网格)。
否则,这里有更复杂的代码来设置imageBrush的确切像素宽度和高度。
https://stackoverflow.com/questions/19363218
复制相似问题