AathifMahir / MauiIcons

MauiIcons is Icon Collection Library for .Net Maui
MIT License
196 stars 13 forks source link

Can't use Binding in IconColor, in a scenario where the app color changes due to an user's choice #95

Closed FelipePedrotiRaymundo closed 4 months ago

FelipePedrotiRaymundo commented 4 months ago

Describe the bug I'm trying to use Binding in IconColor, but this error message pops-up: No property, BindableProperty, or event found for "IconColor", or mismatching type between value and property.

To Reproduce

<tabView:SfTabItem Header="Jogos" ImagePosition="Top" TextColor="{Binding TabBarTextColor }" ImageSource="{icons:FontAwesomeSolid Gamepad, IconColor={Binding TabBarTextColor}}">
                    <tabView:SfTabItem.Content>

                    </tabView:SfTabItem.Content>
                </tabView:SfTabItem>

Expected behavior The IconColor property can be set using Binding

A temporary solution for my case is a little neat, but works: I need to set a Resource in my content page, set the ImageSource as a DynamicResource and set this resource in code

<ContentPage.Resources>
        <Color x:Key="TabBarTextColor">#fff</Color>
        <FontImageSource x:Key="ImageGamepad" />
        <FontImageSource x:Key="ImageShuttleSpace" />
    </ContentPage.Resources>

Resources["ImageGamepad"] = FontAwesomeSolidIcons.Gamepad.ToImageSource(ResourceUtils.GetCurrentPlatformColor());
        Resources["ImageShuttleSpace"] = FontAwesomeSolidIcons.ShuttleSpace.ToImageSource(ResourceUtils.GetCurrentPlatformColor());

Desktop and Smartphone (please complete the following information):

Additional context The user can select what game console they are seeing, and depending on what game console is select, the app color changes accordingly.

AathifMahir commented 4 months ago

@AathifMahir Can you check whether other Markup Extension like FontImageSource that built into maui Enables Binding Support?

FelipePedrotiRaymundo commented 4 months ago

If I use FontImageSource as a resource, the binding works because I can set a breakpoint at the Property and it stops at it, but the font color aways stay in white. If I use DynamicResource I need to still set it in code to work.Get Outlook for Android

AathifMahir commented 4 months ago

If I use FontImageSource as a resource, the binding works because I can set a breakpoint at the Property and it stops at it, but the font color aways stay in white. If I use DynamicResource I need to still set it in code to work.Get Outlook for Android

As far as I looked through the source codes of FontImageSource Markup Extension, it does only create a new FontImageSource at initialization, doesn't detect changes creates a new one, this is exactly same for MauiIcons as well, Since binding is crucial part of Xaml, I'll look through the possibility of enabling binding support for MauiIcons.

The problem, we are facing here is we are creating a new object of FontImageSource instead of using font directly therefore responding to changes is little complex.

FelipePedrotiRaymundo commented 4 months ago

I'll appreciate if its possible to use binding, because all the logic and theming relay on it in my app. If the colors can't change in realtime problem solved, but it can. Also, for my initial release can't be a problem, because I will accept only on game console, and can let the colors as StaticResource, but for future releases I will need to change all this behavior if the colors are fixed

AathifMahir commented 4 months ago

I'll appreciate if its possible to use binding, because all the logic and theming relay on it in my app. If the colors can't change in realtime problem solved, but it can. Also, for my initial release can't be a problem, because I will accept only on game console, and can let the colors as StaticResource, but for future releases I will need to change all this behavior if the colors are fixed

Yeah, I'll add this as feature request and will try to implement this as soon as possible

AathifMahir commented 4 months ago

@FelipePedrotiRaymundo Started Working on this Issue with Following PR #96 , I Would like you clarify whether OnPlatforms and OnIdioms Does need Binding Support Too? As far of Usage I can't think of Many and Also I would Appreciate if you have any further feedback to make this feature as completed implementation

Edit: v2.2.0-pre is Available Now in Nuget with Binding Support, Feel free to try it out and let me know

AathifMahir commented 4 months ago

Done with #96