question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't specify the color of an SVG image

See original GitHub issue

Description

I’m trying to use an SVG image in my project but I can’t specify the color. The Image color doesn’t have a ForeColor property. How to change the color in xaml or codebehind? Note that I would like to use the same image but with different colors.

As an alternative I tried to set the color using the TintColor property in the project file, but that doesn’t seem to work. The image always renders black.

This is the project file:

<ItemGroup> <None Remove="Resources\Images\delete.svg" TintColor="#FF0000" BaseSize="50,50" /> <None Remove="Resources\Splash\splash.svg" /> </ItemGroup>

And this is the result:

image

I’m kind of puzzled that we should set the color in the project file, instead of a property on the Image itself.

Steps to Reproduce

  1. Create a new Maui project
  2. Add an SVG image to the project and set the color as described above
  3. Run the project, image stays black

Link to public reproduction project repository

None

Version with bug

6.0.400

Last version that worked well

Unknown/Other

Affected platforms

Android, I was not able test on other platforms

Affected platform versions

All Android

Did you find any workaround?

No response

Relevant log output

No response

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Jabbah76commented, Nov 8, 2022

OK, I have figured out the exact notation to make it work

<MauiImage Update="Resources\Images\delete.svg" TintColor="#FF0000" BaseSize="50,50" />

Note it should be Update instead of Include

However, I still think specifying the color of the SVG image in the project file is not the way to go as you could use the same image with different colors. Can a solution for this be considered?

I will also try Phenek’s workaround, but something out of the box would be nice

Edit: Just saw that the Community Toolkit has the IconTintColorBehavior, which is good enough for me

0reactions
myrupcommented, Nov 14, 2022

@PureWeen Is this really closeable? It seems like something that should just be working out-of-the-box.

Perhaps a TintColor attribute on Image.

Read more comments on GitHub >

github_iconTop Results From Across the Web

I can't change the fill color of a SVG Sprite
You have to remove internal styling of fill property and only apply css property. Either way change fill property of svg using javascript ......
Read more >
Can't change SVG Colour
If you want to change its color, you need to modify the SVG's code directly and upload it to your media library again....
Read more >
Change Color of SVG on Hover
SVG can be set as a background image just like PNG, JPG, or whatever other graphics format. At this point, you've sort of...
Read more >
I can't change the color of the SVG and PNG icons.
It is possible to change the colours in SVG's. Since SVG is basically a text file you can edit it in your preferred...
Read more >
[Fix] CSS SVG fill not working - Weekend Projects
We can change the color of a SVG path or element with the fill property. However theres many ways to get it wrong....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found