Hi Antonio, When the file does exist, you can load it into memory by doing something like:
byte[] imageBytes = null;
imageBytes = File.ReadAllBytes(fileName);
Next, when you want to create an ImageBrush to assign as a Background, you can do something like:
using (MemoryStream ms = new MemoryStream(imageBytes))
{
BitmapImage img= new BitmapImage();
img.BeginInit();
img.CacheOption = BitmapCacheOption.OnLoad;
img.StreamSource = ms;
img.EndInit();
ImageBrush imBrush = new ImageBrush();
imBrush.ImageSource = img;
DockPanel.Background = imBrush;
}
Use a try...catch in case the image is bad, or you may want to make that determination right after loading the image file into memory (depends upon your app). Note: you could also use BitmapFrame.Create(ms, BitmapCreateOptions.None, BitmapCacheOption.OnLoad) to create an ImageSource instead of the BitmapImage and it's BeginInit and EndInit.
Blog: http://windowsclientdevelopment.spaces.live.com FAQs: http://windowspresentationfoundation.wikispaces.com http://windowsmobile.wikispaces.com http://vsto.wikispaces.com