Xamarin.Forms icon indicating copy to clipboard operation
Xamarin.Forms copied to clipboard

[Bug] Color of FontImageSource does not change when Button is disabled

Open TechWatching opened this issue 6 years ago • 5 comments
trafficstars

Description

When a button which contains a FontImageSource and a text is disabled, only the text takes a different disabled color, not the fontImageSource.

Steps to Reproduce

  1. Create a button with an FontImageSource as the ImageSource and a text
  2. Disable the button
  3. The color of the text is changed but not the color of the icon of the FontImageSource

Expected Behavior

Both the text and the icon should have the same disabled color.

Actual Behavior

Only the text has a disabled color, not the icon.

Basic Information

  • Version with issue: Xamarin Forms 4.1
  • IDE: VS 2019

Screenshots

image

TechWatching avatar Jul 10 '19 08:07 TechWatching

@TechWatching Can you please attach a small project that demonstrates this issue? Thanks!

samhouts avatar Jul 11 '19 02:07 samhouts

I don't know how @TechWatching has set up his button, but I've got a similar issue. I've bound the color of the fontimagesource to the button TextColor, and when the button is disabled I'm assuming that the button text color isn't actually changing, it's just done in the renderer part? With the code below, the image in the button will always be red, and the text will switch from red to dark grey when the button is disabled.

    <StackLayout>
        <!--  Place new controls here  -->
        <Label HorizontalOptions="Center" Text="Button enabled?" />
        <Switch x:Name="DisableButtons" HorizontalOptions="Center" IsToggled="True" />
        <Button x:Name="ActionButton"
                CornerRadius="0"
                FontSize="26"
                IsEnabled="{Binding Source={x:Reference DisableButtons}, Path=IsToggled}"
                Text="Material Button"
                TextColor="Red"
                Visual="Material">
            <Button.ImageSource>
                <FontImageSource FontFamily="Roboto-Black"
                                 Glyph="A"
                                 Size="26"
                                 Color="{Binding Source={x:Reference ActionButton}, Path=TextColor}" />
            </Button.ImageSource>
        </Button>
    </StackLayout>

A workaround is using a trigger to have a different FontImageSource depending on the button state, ie something like this:

        <Button x:Name="ActionButton"
                CornerRadius="0"
                FontSize="26"
                IsEnabled="{Binding Source={x:Reference DisableButtons}, Path=IsToggled}"
                Text="Material Button"
                TextColor="Red"
                Visual="Material">
            <Button.Triggers>
                <Trigger TargetType="Button" Property="IsEnabled" Value="False">
                    <Setter Property="ImageSource">
                        <FontImageSource FontFamily="Roboto-Black"
                                         Glyph="A"
                                         Size="26"
                                         Color="Gray" />
                    </Setter>
                </Trigger>
            </Button.Triggers>
            <Button.ImageSource>
                <FontImageSource FontFamily="Roboto-Black"
                                 Glyph="A"
                                 Size="26"
                                 Color="{Binding Source={x:Reference ActionButton}, Path=TextColor}" />
            </Button.ImageSource>
        </Button>

Doesn't necessarily match the text color but at least it looks disabled.

MitchBomcanhao avatar Jul 11 '19 09:07 MitchBomcanhao

Yes exactly the same problem and the same workaround.

TechWatching avatar Jul 11 '19 11:07 TechWatching

I have created a sample where I can reproduce the same problem with the version 4.1.

Test6836.zip

jsuarezruiz avatar Jul 16 '19 12:07 jsuarezruiz

Still present on MAUI unfortunately

Jon2G avatar Aug 17 '22 02:08 Jon2G