As I started doing more and more work in WPF, I had to port my "About" dialog. In attempt to keep everything clean of Windows Forms that also meant that I need to find another way of loading icon (since Bitmap class is not part of WPF).
Code follows same logic as one for Windows Forms. Only important difference is use of ImageSource as our final destination.
var hLibrary = NativeMethods.LoadLibrary(Assembly.GetEntryAssembly().Location);
if (hLibrary != IntPtr.Zero) {
var hIcon = NativeMethods.LoadIcon(hLibrary, "#32512");
if (hIcon != IntPtr.Zero) {
return Imaging.CreateBitmapSourceFromHIcon(hIcon, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
}
}
Without further ado, here is full sample.