Bug 25661 - ToolBarItem not showing as disabled when CanExecute is set to false
Summary: ToolBarItem not showing as disabled when CanExecute is set to false
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms (show other bugs)
Version: 1.4.3
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-12-30 19:23 UTC by Jon Goldberger [MSFT]
Modified: 2017-09-04 21:57 UTC (History)
9 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Test Project (5.63 MB, application/zip)
2014-12-30 19:23 UTC, Jon Goldberger [MSFT]
Details
Test project demonstrating bug 25661 with XF 1.4.2.6359 (72 bytes, text/plain)
2015-06-17 11:48 UTC, Daniel May
Details
Toolbar Item doesn't disable when CanExecute returns false (85.75 KB, application/x-zip-compressed)
2016-01-23 10:14 UTC, Shane
Details
Demonstrate disable behavior on WINRT vs Android (91.98 KB, application/x-zip-compressed)
2016-03-25 23:10 UTC, Shane
Details

Description Jon Goldberger [MSFT] 2014-12-30 19:23:12 UTC
Created attachment 9214 [details]
Test Project

## Description

This may be "as designed" per this bug report: https://bugzilla.xamarin.com/show_bug.cgi?id=24576

However it seems that the ToolBaritem should show as disabled/hidden when CanExecute is set to false.

## Steps to reproduceTested on Forms 

1. Open the attached test project in Visual Studio.
2. Deploy to Windows Phone emulator (or iOS or Android)

Expected result: Submit button will show as disabled or hidden.

Actual result: Submit button shows as enabled.


## Note 

Change "false" to "true" on line 33 of App.cs in the Forms PCL project to enable the submit button. Once done you will see no change in the appearance of the Submit button as compared to when it is disabled. 

tested on forms version 1.3.0.6292
Comment 2 Rajneesh Kumar 2014-12-31 00:07:57 UTC
I have checked this issue and able to reproduce this. To reproduce this issue I have followed the steps and helped provided in bug description.

Steps i followed:
1. Open the attached test project in VS.
2. Set android as start-up project.
3. Build and deploy it on emulator.
4. Observed that submit button is disabled.
5. Change "false" to "true" on line 33 of App.cs.
6. Deploy it again and observed that no change in the appearance of the Submit button

Screencast: http://www.screencast.com/t/aVoJysPNLp

I observed that there is no change in the appearance of the Submit button as compared to when it is disabled. 

Application output: https://gist.github.com/Rajneesh360Logica/feca3b5a243bff087ad7
adb log: https://gist.github.com/Rajneesh360Logica/0c6f42d7902a547086b7
Vs trace logs: http://www.screencast.com/t/QAHZQ4atReVS

Environment Info:

Xamarin.Forms Version: 1.3.0.6292 

Microsoft Visual Studio Professional 2013
Version 12.0.30723.00 Update 3
Microsoft .NET Framework
Version 4.5.50938

Installed Version: Professional

LightSwitch for Visual Studio 2013   06177-004-0446016-02381
Microsoft LightSwitch for Visual Studio 2013

Team Explorer for Visual Studio 2013   06177-004-0446016-02381
Microsoft Team Explorer for Visual Studio 2013

Visual Basic 2013   06177-004-0446016-02381
Microsoft Visual Basic 2013

Visual C# 2013   06177-004-0446016-02381
Microsoft Visual C# 2013

Visual C++ 2013   06177-004-0446016-02381
Microsoft Visual C++ 2013

Visual F# 2013   06177-004-0446016-02381
Microsoft Visual F# 2013

Visual Studio 2013 Code Analysis Spell Checker   06177-004-0446016-02381
Microsoft® Visual Studio® 2013 Code Analysis Spell Checker

Portions of International CorrectSpell™ spelling correction system © 1993 by Lernout & Hauspie Speech Products N.V. All rights reserved.

The American Heritage® Dictionary of the English Language, Third Edition Copyright © 1992 Houghton Mifflin Company. Electronic version licensed from Lernout & Hauspie Speech Products N.V. All rights reserved.

Windows Phone SDK 8.0 - ENU   06177-004-0446016-02381
Windows Phone SDK 8.0 - ENU

Application Insights Tools for Visual Studio Package   1.0
Application Insights Tools for Visual Studio

ASP.NET and Web Tools   12.3.50717.0
Microsoft Web Developer Tools contains the following components:
Support for creating and opening ASP.NET web projects
Browser Link: A communication channel between Visual Studio and browsers
Editor extensions for HTML, CSS, and JavaScript
Page Inspector: Inspection tool for ASP.NET web projects
Scaffolding: A framework for building and running code generators
Server Explorer extensions for Microsoft Azure Websites
Web publishing: Extensions for publishing ASP.NET web projects to hosting providers, on-premises servers, or Microsoft Azure

ASP.NET Web Frameworks and Tools 2012.2   4.1.21001.0
For additional information, visit http://go.microsoft.com/fwlink/?LinkID=309563

ASP.NET Web Frameworks and Tools 2013   5.2.20703.0
For additional information, visit http://www.asp.net/

Common Azure Tools   1.2
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Microsoft Advertising SDK for Windows Phone   
Microsoft Advertising SDK for Windows Phone
Build 

Microsoft Azure Mobile Services Tools   1.2
Microsoft Azure Mobile Services Tools

NuGet Package Manager   2.8.50926.663
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

Office Developer Tools for Visual Studio 2013 ENU   12.0.30626
Microsoft Office Developer Tools for Visual Studio 2013 ENU

PowerShell Tools   1.2
Provides file classification services using PowerShell

PreEmptive Analytics Visualizer   1.2
Microsoft Visual Studio extension to visualize aggregated summaries from the PreEmptive Analytics product.

SQL Server Data Tools   12.0.30919.1
Microsoft SQL Server Data Tools

Windows Phone 8.1 SDK Integration   1.0
This package integrates the tools for the Windows Phone 8.1 SDK into the menus and controls of Visual Studio.

Workflow Manager Tools 1.0   1.0
This package contains the necessary Visual Studio integration components for Workflow Manager.

Xamarin   3.8.150.0 (10cfd178d55287f09c85f5a1e604dfe20889a40f)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android   4.20.0.28 (ba9bbbdd44cfdc4bf485e8885bd2ad24fba525f7)
Visual Studio plugin to enable development for Xamarin.Android.

Xamarin.iOS   8.4.0.0 (840a925103a0bf4a856507f13d5eaee3c1579c2f)
Visual Studio extension to enable development for Xamarin.iOS.
Comment 3 Jason Smith [MSFT] 2015-01-13 13:51:02 UTC
Should be fixed in 1.3.2-pre1
Comment 4 Rajneesh Kumar 2015-01-23 09:00:26 UTC
I have checked this issue with the following builds:

Microsoft Visual Studio Professional 2013
Version 12.0.30723.00 Update 3
Microsoft .NET Framework
Version 4.5.50938
Xamarin   3.9.236.0 (d6a2cae)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.
Xamarin.Android   4.20.0.34 (49a04b966feb40dfdba49d57ba16249b66d606a6)
Visual Studio plugin to enable development for Xamarin.Android.
Xamarin.iOS   8.6.0.0 (eb24bdcf5cba2c12b673a07e0a8cce368b9563b3)
Visual Studio extension to enable development for Xamarin.iOS.
Xamarin.iOS Unified Migration   1.0
Automated migration for Xamarin iOS Classic projects to Unified

I observed that ToolBarItem is showing as disabled when CanExecute is set to false, and it is showing as enabled when CanExecute is set to true. This issue is working fine.Here is the screencast for the same: http://www.screencast.com/t/apD08uv2H

This issue has been fixed, hence closing this issue.
Comment 5 Daniel May 2015-06-17 11:36:23 UTC
# This bug still occurs in iOS with XF Version 1.4.2.6359, sadly I am not presently able to test Android or Windows Phone.

I have attached the same test project, with an updated Xamarin.Forms package to 1.4.2.6359 and the issue is reproducible on iOS.

The same description, steps and notes from Jon Goldberger's above comment apply.
Comment 6 Daniel May 2015-06-17 11:48:29 UTC
Created attachment 11647 [details]
Test project demonstrating bug 25661 with XF 1.4.2.6359
Comment 7 Daniel May 2015-06-17 11:49:19 UTC
Attachment was too large (8.6mb), so made available through Dropbox using the following link (or see attachment):

https://www.dropbox.com/s/czqaau4hfyihps1/FormsPlayground_1.4.2.6359.zip
Comment 8 Seth Rosetter 2015-06-17 15:14:24 UTC
Hi Daniel,

I have tested against Xamarin.Forms 1.4.2 with your provided sample and have been unable to reproduce locally. I have tested both Android and iOS and the behavior seems correct. (when CanExecute is false, the toolbar item is disabled, when it is set to true, it is enabled). I did see some package reference artifacts in your iOS .csproj referencing elements from Xamarin.Forms 1.3.0. Perhaps this was resulting in unexpected behavior? 

I tested against an iPod Touch device running 7.1.1 and a Nexus 5 device running 5.0. Can you provide me the device specifics you are testing on? Marking NEEDINFO for the time being, please reopen one you have responded.
Comment 9 Olivier Ansquer 2016-01-22 14:27:57 UTC
It seems that I have the same problem.
On android, when a ToolBarItem displays only an icon, the user cannot know visually if the command can be executed or not.
The problem seems to be discussed here :

http://stackoverflow.com/questions/9642990/is-it-possible-to-grey-out-not-just-disable-a-menuitem-in-android

Can you do something or hide TootbarItems on Android when CanExecute = false ?

Thanks,

Olivier
Comment 10 Shane 2016-01-23 10:14:45 UTC
Created attachment 14694 [details]
Toolbar Item doesn't disable when CanExecute returns false

If you click the white refresh button in the top right corner of the app... You'll notice the button (which is tied to the same command) disables but the refreshWhite Icon stays looking white and enabled.... On iOS and Windows Phone the icon greys out as if it's disabled... If you keep clicking the white refresh toolbar item it won't execute while it's disabled. Even though it looks enabled.
Comment 12 Olivier Ansquer 2016-01-24 10:08:55 UTC
I finally have found a solution.
If the ToolbarItem is defined as this :

<ToolbarItem Order="Primary" Priority="0" Icon="synchronize.png" />

In the Drawable folder of the Android Project, create a file named synchronize.xml with this content :

<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item
      android:state_enabled="false"
      android:drawable="@drawable/synchronize_disabled" />
  <item
      android:state_enabled="true"
      android:drawable="@drawable/synchronize_enabled" />
</selector>

In the same folder, create a file named synchronize_enabled.png with your normal icon.

And finally, always in the same folder, create a last file named synchronize_disabled.xml with this content :

<?xml version="1.0" encoding="utf-8" ?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/synchronize_enabled"
    android:alpha="178">
</bitmap>
Comment 13 Jason Smith [MSFT] 2016-03-25 19:19:38 UTC
Thank you for taking the time to submit this report. After reviewing the description of this bug, we no longer believe it affects the current version of Xamarin.Forms. If you are still experiencing the issue after updating your packages, please reopen this report with an attached reproduction.
 
For your convenience, we have created some reproduction best practices viewable here: https://gist.github.com/jassmith/92405c300e54a01dcc6d

Warm regards,
Xamarin Forms Team
Comment 14 Shane 2016-03-25 23:10:19 UTC
Created attachment 15529 [details]
Demonstrate disable behavior on WINRT vs Android

In the attached project if you click the refresh button it triggers a command that delays for 5 seconds and then sets CanExecute to True...

On windows the button turns grey during the period CanExecute is false whereas on Android it just stays white
Comment 15 Shane 2016-03-25 23:12:00 UTC
Xamarin Forms "2.1.0.6529"
Not sure if I can re-open this bug or not since I'm not the original creator

=== Xamarin Studio ===

Version 5.10.3 (build 26)
Installation UUID: 5f3e1f3d-a9ab-4075-8548-c0cc8f9cf6e1
Runtime:
	Microsoft .NET 4.0.30319.42000
	GTK+ 2.24.23 (MS-Windows theme)
	GTK# 2.12.30

=== Xamarin.Profiler ===

Version: 0.30.0
Location: C:\Program Files (x86)\Xamarin\Profiler\XamarinProfiler.exe

=== Xamarin.Android ===

Version: 6.0.2.1 (Business Edition)
Android SDK: H:\SDKs\android-sdk
	Supported Android versions:
		2.3   (API level 10)
		4.0.3 (API level 15)
		4.1   (API level 16)
		4.2   (API level 17)
		4.4   (API level 19)
		5.0   (API level 21)
		5.1   (API level 22)
		6.0   (API level 23)

SDK Tools Version: 24.4.1

SDK Platform Tools Version: 23.1.0

SDK Build Tools Version: 23.0.2


Java SDK: C:\Program Files (x86)\Java\jdk1.7.0_55
java version "1.7.0_55"
Java(TM) SE Runtime Environment (build 1.7.0_55-b13)
Java HotSpot(TM) Client VM (build 24.55-b03, mixed mode, sharing)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Xamarin Android Player ===

Not Installed

=== Build Information ===

Release ID: 510030026
Git revision: ac9b7fcba9ee92ac30c8eb90f20c2228ce033efa
Build date: 2016-03-01 19:16:08-05
Xamarin addins: 633fde3bf405e3c402a51980976c431c204cf4f6
Build lane: monodevelop-windows-cycle6-c6sr2

=== Operating System ===

Windows 10.0.10240.0 (64-bit)
Comment 16 Jon Goldberger [MSFT] 2016-03-26 01:05:39 UTC
@Shane,

Did you try the suggestion in comment 12 for getting this to work on Android? If yes, and still getting the issue, I would recommend filing a new bug report as this one is old and fixed so you may be hitting a new issue. 

If the suggestion in comment 12 works for you, then that would be an issue of differing behavior on the platform itself as to how the native platform controls show themselves as disabled/enabled rather than a bug in Xamarin Forms per se.
Comment 17 Shane 2016-03-26 01:48:38 UTC
Yea that works :-) I just wasn't sure if "fixed" implied "fixed" or by design...  And it looks like for Android there's not really an implicit "disabled" like on iOS and Win**

There's ways but that would probably make Xam Forms a bit too opinionated in relation to Android....  Thank you for the follow up. The "Comment 12" way works well enough for now :-)
Comment 18 Alexander 2017-03-21 12:49:45 UTC
The suggestion in comment 12 stops working in 2.3.4.
Any XML drawables could not be used, it causes the following in log:

E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: /ic_delete_white_24dp: open failed: ENOENT (No such file or directory)
Comment 19 Alexander 2017-03-23 15:09:09 UTC
The functionality suggested in comment 12 was broken by https://github.com/xamarin/Xamarin.Forms/pull/437
Comment 20 Alexander 2017-03-29 18:31:34 UTC
>The functionality suggested in comment 12 was broken by >https://github.com/xamarin/Xamarin.Forms/pull/437

Should be fixed in 2.3.4-pre6.
Comment 21 Mahmoud Ali 2017-09-04 21:57:25 UTC
This still happens when there is only text (no icon) in the ToolbarItem.

Note You need to log in before you can comment on or make changes to this bug.