Xamarin.forms: Disabled ToolbarItem with an icon on Android is not "grayed out"

Created on 27 Jul 2018  路  7Comments  路  Source: xamarin/Xamarin.Forms

Description

I have a ToolBarItem defined like

<ToolbarItem Order="Primary" Text="Next" Icon="next.png" IsEnabled="False" />

On iOS and UWP the icon is grayed out when the control is set to disabled. On Android the icon is showing the original color. If I remove the icon and use only text, then the text changes color as expected when the control is disabled.

Steps to Reproduce

  1. Create a form and add four items. Two with an icon and two without.
<ContentPage.ToolbarItems>
    <ToolbarItem Order="Primary" Icon="next.png" IsEnabled="False" />
    <ToolbarItem Order="Primary" Icon="next.png" IsEnabled="True" />

    <ToolbarItem Order="Primary" Text="Next" IsEnabled="False" />
    <ToolbarItem Order="Primary" Text="Next" IsEnabled="True" />
</ContentPage.ToolbarItems>

  1. Test the application and you see the text versions are displayed differently, while the icon ones are looking the same.

Expected Behavior

I expect the icon to be rendered in a disabled state, as is the case on UWP and iOS.

Actual Behavior

Icon is rendered the same in both enabled and disabled state.

Basic Information

  • Version with issue: 3.1.0.637273
  • Last known good version:
  • IDE:
  • Platform Target Frameworks:

    • Android: 8.1

  • Android Support Library Version: 27.0.2.1

Screenshots

image

3 Android bug

Most helpful comment

I personally classify this as a bug but it would be a functionality change as well. We'll need to discuss this with PM

All 7 comments

I personally classify this as a bug but it would be a functionality change as well. We'll need to discuss this with PM

Hi @jassmith, What's the status of Pull Request ? will it be fixed soon? we really need this please.

Hi @jassmith, how is it going after few months? Is there any inconvenience or difficulty in implementing it, or it's just a low priority? From company site this feature is really awaited because with the current implementation of the forms toolbar it's impossible to workaround this issue, without reimplementing completely the toolbar control.

Could you let us know if are you going to fix it in near future, or we should start to implement our own toolbar control?

Thanks,

I set up a custom control that removes the image from the toolbar item whenever the item is disabled, and adds it again whenever the item is enabled. I know my use case is very specific, but this really simple approach might be a useful workaround for some while the issue is not fixed.

public class DisableableToolbarItem : ToolbarItem
{
    private FileImageSource _fileImageSource;

    protected override void OnPropertyChanged(string propertyName)
    {
        if (propertyName == DisableableToolbarItem.IsEnabledProperty.PropertyName)
        {
            if (this.IsEnabled)
            {
                this.Icon = _fileImageSource;
            }
            else
            {
                _fileImageSource = Icon;
                this.Icon = null;
            }
        }
        base.OnPropertyChanged(propertyName);
    }
}

You could even have 2 images that flip whenever the IsEnabled property changes, that wouldn't be difficult either.

Isn't this pull request #3773 already addressing this issue? It is already merged.

Just tested with the latest Xamarin.Forms and works as expected :)

Still reproduces on 4.2.0.709249, the IsEnabled property is ignored and the command is executing regardless of the value of IsEnabled.

Was this page helpful?
0 / 5 - 0 ratings