XAML . NET MAUI是否更改图标前景?

krugob8w  于 2022-12-07  发布在  其他
关注(0)|答案(1)|浏览(235)

I have a .NET Maui project which uses a flyout style menu, in said menu I have icons and titles, if you are familiar with .NET Maui you'll understand what I mean, exactly like in the Microsoft Docs example.
My Icons, for example I use information icon that in the shell that leads to the about page, the icon is black over transparent .svg.
And when the user uses the light theme, everything is fine, but when the user switches to dark theme, the background becomes black and the icon doesn't change color obviously so it is no longer visible.
I checked for a foreground color property and Image doesn't have one... I can probably drop the icon in photoshop and make a white version, and then in the visual states I can change the ImageSource , but firstly, it seems overkill when I have multiple icons like this, it also means I would have about twice the number of resources in the application package, and means I have to define the template for each shell which is just seems wrong, or create a custom Image control with 2 sources and switch between them.
I can't help but wonder if there is a better way to do this as I am sure black icons with dark themes are a very common problem.
I tried searching it in the shell, image, and .NET Maui docs, also tried googling the issue and even checked xamarin forms for this since they are pretty similar in terms of API's, I did find anything...

wko9yo5t

wko9yo5t1#

I had the same problem and at the moment the only solution it's what you said, if you follow the microsoft docs you can see this link that explain how to change the themes of the same image in light/dark style.
I recommend you to save time, that if possible choose images without a transparent background so as not to have to edit icon by icon.
Also, MAUI community is very active, so you can post this issue on the MAUI Repo to suggest this feature you said!
Finally, i recommend you icons there are all <10kb size and looks nice light/dark theme

相关问题