public void PopulateBrushes() { Brushes.Clear(); // Need to automate this to find all png files in res folder (make it res/tiles?) string[] files = Directory.GetFiles(@"..\..\..\Test\res\sprites\tiles", "*.png", SearchOption.TopDirectoryOnly); List <string> ls = new List <string>(files); ls.AddRange(Directory.GetFiles(@"..\..\..\Test\res\sprites\entities", "*.png", SearchOption.TopDirectoryOnly)); foreach (var x in ls) { ImageBrush brush = new ImageBrush(); BitmapImage bmi = new BitmapImage(new Uri(x, UriKind.Relative)); if (bmi.PixelWidth > 32 || bmi.PixelHeight > 32) { BitmapSource bms = new CroppedBitmap(bmi, new Int32Rect(0, 32, 32, 32)); brush.ImageSource = bms; } else { brush.ImageSource = bmi; } Brushes.Add(x.Split('\\').Last(), brush); } }