Maui icon indicating copy to clipboard operation
Maui copied to clipboard

[BUG] IconTintColorBehavior is reset when navigate to another page then back

Open zenith6495 opened this issue 1 year ago • 5 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Did you read the "Reporting a bug" section on Contributing file?

  • [X] I have read the "Reporting a bug" section on Contributing file: https://github.com/CommunityToolkit/Maui/blob/main/CONTRIBUTING.md#reporting-a-bug

Current Behavior

IconTintColorBehavior for image is reset to black color when you navigate to another page then back to current page.

Expected Behavior

IconTintColorBehavior for image should remain the same when navigate to another page then to the current page.

Steps To Reproduce

  1. Set IconTintColorBehavior of an Image to red color for example.
  2. Navigate to another page using Shell.GotoAsync.
  3. Go back to the previous page, where icon is tinted to red.
  4. Notice the tinted image is reset back to black color.

Note: I noticed this issue in the latest version community toolkit sample project as well.

Link to public reproduction project repository

https://github.com/CommunityToolkit/Maui/tree/main/samples

Environment

- .NET MAUI CommunityToolkit: 9.0.1
- OS: Windows
- .NET MAUI: 8.0.60

Anything else?

No response

zenith6495 avatar Jun 20 '24 04:06 zenith6495

Thanks for logging this. I'm experiencing the same issue. Also seeing the tint color reset to white after a DataTrigger changes the tint color and then changes it back.

kkppstudios avatar Jun 20 '24 22:06 kkppstudios

Thanks for this. I'm experiencing the same issue on IOS even when the app goes background and then comes back.

TheSundayDev avatar Jul 09 '24 07:07 TheSundayDev

Hi all, just to know. this issue is also on IOS. The fix above is also for IOS? thanks a lot

TheSundayDev avatar Aug 06 '24 08:08 TheSundayDev

I've noticed that by forcing a property change on the control that the image button has the behavior on will cause it to reevaluate it. Sadly this work around doesn't work if the Image buttons are in a collection.

Saurbaum avatar Aug 14 '24 10:08 Saurbaum

Hi, it seems that the issue is partially solved from last version of CT (9.0.2). Now when I go to a new page the color is alwasy applied. The only issue I can still see is that when I come back to prev page, if you are using behavior in list view items, the color is wrong in some elements (eg instead to be applied to 2nd element is applied to the first.. ).

TheSundayDev avatar Aug 14 '24 13:08 TheSundayDev

I have similar issue with a Button with an ImageSource and a IconTintColorBehavior applied. My image is an SVG (using its automatically created PNG clone in XAML definition). Going to another page and then back (using built-in back navigation button) didn't apply the custom tint of my image button. I'm using 9.1.0 version of the Toolkit, using Windows Machine. It worked though on android emulator.

elTRexx avatar Oct 26 '24 04:10 elTRexx

Hi, the bug is still open and it's the same of ths issue #2275 IconTintColorBehavior is my nightmare and it's blocking me to migrate to MAUI :(

TheSundayDev avatar Oct 26 '24 10:10 TheSundayDev

@TheSundayDev can you please try testing the result of this PR: https://github.com/CommunityToolkit/Maui/pull/2304 and add in the ApplyOn property to your behavior usage? Set it to OnViewLoaded.

bijington avatar Oct 27 '24 07:10 bijington

@TheSundayDev can you please try testing the result of this PR: #2304 and add in the ApplyOn property to your behavior usage? Set it to OnViewLoaded.

Hi, thanks a lot for your commitment, much appreciated! I'm going to test asap. Just one question, since there is an issue I think that that fix should be apply by default and not setting a parameter. Am I wrong?

TheSundayDev avatar Oct 27 '24 14:10 TheSundayDev

I get your point but that would be a behavioral change. We haven't had many people report this issue so either they aren't seeing it or aren't using the behavior. If it's a common issue then it would be wise to change the default behavior

bijington avatar Oct 27 '24 15:10 bijington

Thanks a lot for your super quick answer, thanks! Can you tell me how to test your PR? thanks

TheSundayDev avatar Oct 27 '24 16:10 TheSundayDev

@TheSundayDev you can follow this page to pull down the build from the PR: https://github.com/CommunityToolkit/Maui/wiki/Preview-Packages

bijington avatar Nov 02 '24 20:11 bijington

hi, in order to test all test must be passed? thanks

TheSundayDev avatar Nov 07 '24 21:11 TheSundayDev

Hi, no news for this PR? thanks

TheSundayDev avatar Nov 22 '24 12:11 TheSundayDev

We have some pipeline failures which I haven't worked out the cause yet. You can probably still grab the preview build though

bijington avatar Nov 23 '24 08:11 bijington

Are there any updates on this item? This issue still persist.

WEUDE avatar Jan 02 '25 16:01 WEUDE

Hello, if you pardon me for asking for update, I though you resolved the issue, so I updated my version to last one 11.1.0, but the Icon tint color isn't correctly working (first time OK, then on back navigation not anymore). I've tested it on Windows Machine, with 2 nested navigation pages (Home -> Selected Item -> Edit Item <- Selected Item <- Home). I saw you reverted the PR, so maybe it is still on the go for next release? Thanks.

elTRexx avatar Mar 08 '25 23:03 elTRexx

We have the same (or a similar) issue with IconTintColorBehavior.

(Note: We use a copy of IconTintColorBehavior with small changes but I can see the same behaviour whether we use our own or the one from the ToolKit)

When adding a button to a view that is visible, the IconTintColorBehavior is applied as expected. The issue arises when we bind the Button's IsVisible property with our ViewModel and the IsVisible property is false when the IconTintColorBehavior is applied and set to true after some async loading.

We have seen the issue within our Shell and we are using <TabBar>.

One thing I have noticed is that, after loading a Button where the IconTintColorBehavior is not applied correctly, if I switch to a tab with buttons where the IconTintColorBehavior is applied correctly, then switching back to the previous tab, the button image tint color is now applied.

I have applied the changes from #2495 to our custom IconTintColorBehavior (running ApplyTintColor on Loaded-event) and the issue still persist. I may create a repro using IconTintColorBehavior directly from the PR but I cannot promise it right now because I have tight time constraints.

durandt avatar May 07 '25 06:05 durandt

Perhaps we need to also apply the tint when IsVisibke changes

bijington avatar May 07 '25 12:05 bijington

@bijington That was my first thought but it does not seem to help (I tried adding the behaviour when IsVisible changes but it still did not work). What seems to work in my case is to only add the ImageSource to the Button when IsVisible changes to true. So I am starting to wonder if the issue is not something with the image rather than the IconTintColorBehavior (wild guesses). Something like https://github.com/dotnet/maui/issues/14622

durandt avatar May 07 '25 13:05 durandt