Catel.Windows.WindowExtensions.ApplyIconFromApplication C# (CSharp) Method

ApplyIconFromApplication() public static method

Applies the icon from the entry assembly (the application) to the window.
public static ApplyIconFromApplication ( this window ) : void
window this The window.
return void
        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");
            }
        }
    }