public static void ApplyIconFromApplication(this SystemWindow window)
{
Argument.IsNotNull("window", window);
try
{
if (window.Icon != null)
{
return;
}
var currentApplication = Application.Current;
if (currentApplication != null)
{
var entryAssembly = AssemblyHelper.GetEntryAssembly();
if (entryAssembly != null)
{
var icon = Icon.ExtractAssociatedIcon(entryAssembly.Location);
if (icon != null)
{
window.Icon = Imaging.CreateBitmapSourceFromHIcon(icon.Handle,
new Int32Rect(0, 0, icon.Width, icon.Height), BitmapSizeOptions.FromEmptyOptions());
}
}
}
}
catch (Exception ex)
{
Log.Error(ex, "Failed to set the application icon to the window");
}
}
}