The solution proposed by Farhan Anam will work, but it is not perfect: the icon is loaded from the file, converted to a bitmap, saved in the stream, and reloaded from the stream. This is pretty inefficient.
System.Windows.Interop.Imaging CreateBitmapSourceFromHIcon:
private ImageSource IconToImageSource(System.Drawing.Icon icon)
{
return Imaging.CreateBitmapSourceFromHIcon(
icon.Handle,
new Int32Rect(0, 0, icon.Width, icon.Height),
BitmapSizeOptions.FromEmptyOptions());
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
using (var ico = System.Drawing.Icon.ExtractAssociatedIcon(@"C:\WINDOWS\system32\notepad.exe"))
{
image1.Source = IconToImageSource(ico);
}
}
using, . .