Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App icon not showing in build #3755

Closed
PK268 opened this issue Dec 14, 2021 · 13 comments
Closed

App icon not showing in build #3755

PK268 opened this issue Dec 14, 2021 · 13 comments
Labels
area-single-project Splash Screen, Multi-Targeting, MauiFont, MauiImage, MauiAsset, Resizetizer platform/windows 🪟 s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working

Comments

@PK268
Copy link

PK268 commented Dec 14, 2021

Description

Hey, so I'm making an app and I'm trying to change the app icon (you know, the icon that shows in your taskbar) but what i tried doesn't work. This is a code snippet from my .csproj file

<!-- App Icon --> <MauiIcon Include="Resources\app_icon.png" ForegroundFile="Resources\app_icon.png" IsAppIcon="true"/>

I double checked to make sure all the file names and locations were correct. Is there something I'm missing?
Btw I'm not entirely sure what .NET MAUI version I have but I'm pretty sure it's 10 just because when I look at the VS installer there is no update option and 10 is "current".

(Bonus points if you can tell me how to change the app to be a fixed resolution, un-sizeable window)

Steps to Reproduce

  1. Create a new .NET MAUI app
  2. Import image and put into resources folder.
  3. Double click on the .sln
  4. Change app icon Include and ForegroundFile to the path to the file
  5. Save and build for WindowsMachine

Version with bug

Preview 10 (current)

Last version that worked well

Preview 10 (current)

Affected platforms

Windows

Affected platform versions

Windows 11

Did you find any workaround?

No response

Relevant log output

No response

@PK268 PK268 added the t/bug Something isn't working label Dec 14, 2021
@bwoebi
Copy link
Contributor

bwoebi commented Jan 7, 2022

Seems like for unpackaged executables you need to set the icon manually via <ApplicationIcon> property in the csproj.

Would be great if Maui would also be able to handle Win32 icons natively.

@PK268
Copy link
Author

PK268 commented Jan 8, 2022

Het, i don't really see any documentation for ApplicationIcon. How do i use it?

@bwoebi
Copy link
Contributor

bwoebi commented Jan 8, 2022

like <ApplicationIcon>icon.ico</ApplicationIcon> - an embedded resource in ico format.

Then (put it in #if WINDOWS), to also display it in the active window, load it (persist it in some class variable as long as the application lives):

System.Drawing.Icon icon = new(Assembly.GetExecutingAssembly().GetManifestResourceStream("icon.ico")!);

and set it via

WindowHandler.WindowMapper.Add(nameof(IWindow), (handler, view) => {
	IntPtr windowHandle = ((Microsoft.Maui.MauiWinUIWindow)handler.NativeView).WindowHandle;
	PInvoke.User32.SendMessage(windowHandle, PInvoke.User32.WindowMessage.WM_SETICON, (IntPtr)0, icon.Handle);
	PInvoke.User32.SendMessage(windowHandle, PInvoke.User32.WindowMessage.WM_SETICON, (IntPtr)1, icon.Handle);
});

in your Application entry point.

(And kudos to the maui maintainers for making the window handle so easily accessible.)

@PK268
Copy link
Author

PK268 commented Jan 9, 2022

Hey! Thanks again for the response! I have a few problems now. Right now VS isn't recognizing System.Drawing.Icon, PInvoke, or MauiWinUIWindow. Control + space doesn't pull up any results. Also when using ApplicationIcon like you specified, I
get
"Items that are outside Target elements must have one of the following operations: Include, Update, or Remove."
Any fixes for this?

@IIARROWS
Copy link

like <ApplicationIcon>icon.ico</ApplicationIcon> - an embedded resource in ico format.

Then (put it in #if WINDOWS), to also display it in the active window, load it (persist it in some class variable as long as the application lives):

System.Drawing.Icon icon = new(Assembly.GetExecutingAssembly().GetManifestResourceStream("icon.ico")!);

and set it via

WindowHandler.WindowMapper.Add(nameof(IWindow), (handler, view) => {
	IntPtr windowHandle = ((Microsoft.Maui.MauiWinUIWindow)handler.NativeView).WindowHandle;
	PInvoke.User32.SendMessage(windowHandle, PInvoke.User32.WindowMessage.WM_SETICON, (IntPtr)0, icon.Handle);
	PInvoke.User32.SendMessage(windowHandle, PInvoke.User32.WindowMessage.WM_SETICON, (IntPtr)1, icon.Handle);
});

in your Application entry point.

(And kudos to the maui maintainers for making the window handle so easily accessible.)

I'm pretty sure it doesn't work for Android though...
I followed the documentation but it still shows me the blue grid with the bot head.

@bwoebi
Copy link
Contributor

bwoebi commented Jan 24, 2022

For Android the normal MauiIcon works fine for me. This workaround is exclusively for windows.

@IIARROWS
Copy link

Yes, but I have the same problem but for Android.

@AbuMandour
Copy link

Yes, but I have the same problem but for Android.

Me too even in splash screen

@YuqinSong YuqinSong added the s/verified Verified / Reproducible Issue ready for Engineering Triage label Feb 28, 2022
@YuqinSong
Copy link

Verified Repro. Repro project is available:
#3755.zip

@CliffAgius
Copy link
Contributor

I am seeing the same issue with Android and iOS the builds fail complaining they can't find the AppIcon this is VS22 17.2.0 Preview 1.0 and MAUI SDK version of 6.0.200-preview.13

However I solved this by:

  1. using an SVG instead of a PNG
  2. Calling the file the same as the default so appicon.svg
  3. Making it a basic SVG file so before I used InkScape to make the Icon but this had lots of extra stuff in there, so I took the Icon PNG file and used https://convertio.co/ a tool I found with a web search and converted the PNG to SVG.

Not perfect and the issue is still there but with Preview 13 this seems an easy fix.

@IIARROWS
Copy link

I want to say that it works for me now, I think it's from the last update.
I had to manually resize the viewbox of the SVG because to make space for the border, as it was not clear I had to do it (according to Android guidelines https://developer.android.com/guide/practices/ui_guidelines/icon_design_adaptive)

@PK268
Copy link
Author

PK268 commented Mar 14, 2022

I am seeing the same issue with Android and iOS the builds fail complaining they can't find the AppIcon this is VS22 17.2.0 Preview 1.0 and MAUI SDK version of 6.0.200-preview.13

However I solved this by:

  1. using an SVG instead of a PNG
  2. Calling the file the same as the default so appicon.svg
  3. Making it a basic SVG file so before I used InkScape to make the Icon but this had lots of extra stuff in there, so I took the Icon PNG file and used https://convertio.co/ a tool I found with a web search and converted the PNG to SVG.

Not perfect and the issue is still there but with Preview 13 this seems an easy fix.

This fix is only for Android and iOS correct? Will it work on Windows and Mac?

@Redth
Copy link
Member

Redth commented Mar 22, 2022

Only SVG's were supported for app icons up until a more recent release but should be now. Please open a new issue if you still have problems with it.

@Redth Redth closed this as completed Mar 22, 2022
@Redth Redth added the area-single-project Splash Screen, Multi-Targeting, MauiFont, MauiImage, MauiAsset, Resizetizer label Mar 22, 2022
@Redth Redth added this to the 6.0.300-preview.14 milestone Mar 22, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Apr 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-single-project Splash Screen, Multi-Targeting, MauiFont, MauiImage, MauiAsset, Resizetizer platform/windows 🪟 s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants