Currently, I have this in MainWindow.xaml:
<Image Name="LogoImage" />
And this in MainWindow.xaml.cs:
public ImageSource LogoImageSource { get; set; }
....
var rm = new ResourceManager("Project.Properties.Resources", GetType().Assembly);
var logoBmp = (Bitmap) rm.GetObject("CompanyLogo");
if (logoBmp != null)
{
var hBitmap = logoBmp.GetHbitmap();
ImageSource src =
Imaging.CreateBitmapSourceFromHBitmap(
hBitmap,
IntPtr.Zero,
Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions());
LogoImageSource = src;
}
var logoBinding = new Binding("LogoImageSource");
logoBinding.Source = this;
LogoImage.SetBinding(System.Windows.Controls.Image.SourceProperty, logoBinding);
I do it this way because I like to keep images as embedded resources, so there's not a bunch of random files floating around in the users install dir.
But how can I manage the image binding (the last 3 lines of code) from XAML and not C#?
Or, if anyone has any input on how they manage image resources, please share it with me.