iSeller Commerce
iSeller POS Retail
iSeller POS F&B
iSeller POS Express
Crosslight
WebUI
ClientUI
What's New
Download Trial
Web Solution
Mobile Solution
Enterprise Solution
Custom Development
Blog
Community
Latest Development Blogs
ForumPostTopic
Browse By Tag
Okay, so how do we properly bind commands to menu items from the action bar where CanExecute is dynamically changing or raised from a viewmodel? I mean, BindingProvider is the area for all this feature to pair a button id to a command, but CanExecute functions are not working on Android even if DelegateCommand.RaiseCanExecuteChanged() is being called. Regardless if the return value is true or false, it's not doing anything to the menu items... their Enabled states don't change. This doesn't seem to be an issue on iOS. Do we have to call RegisterViewIdentifier or what?
Please advise. Thanks!
Hi Jimmy,To bind CanExecute on ActionBar Items is actually just as you expected to be, we only need to bind ButtonId to BindingProvider then to the Command in ViewModel, then inside the new delegate command we include both Execute and CanExecute method.Also please check this sample because based from our testing, we sucessfully use CanExecute in dynamically changing condition, we also put breakpoints inside the ItemListViewModel.cs. If succeed the Mark Sold button (when you long press an item, the button will appear) will be disabled when it used for sold items. If the problem still persist please inform us, we will be glad to help!Best Regards,Arief
Hi Arief,
Can you confirm the same for DataListViewModelBase? The usual bindings are set, and working on iOS... except for Android. BindingProvider contains pairing of both ButtonId and Commands. The buttons are defined for Android using a menu axml, with the same IDs used with that of the iOS' view controllers. Both are sharing the same viewmodel, as intended for cross platform configurations. The only difference between the two platforms is that... on iOS we have to use RegisterViewIdentifier for the button IDs, and we don;t see how that is being used with Android except for the "this.RegisterViewIdentifier("TableView", this.ListView);" statement. I'm guessing the button IDs are registered with view identifier automatically for Android.
Kindly test this scenario on ListFragment and DataListViewModelBase. As already mentioned, setting the return value of all CanExecute funtions to a static value of true will enable the buttons at runtime, but doesn't change states using dynamic calls. Breakpoints to CanExecute functions suggest that the functions are being called; however, regardless of the values... the buttons don't change to Enabled/Disabled states. That being said, RaiseCanExecuteChanged method are also being called for each delegate commands, but it's not helping.
The current configuration (BindingProvider, ViewModel) works on iOS, but not on Android... so it may be due to the VIEW being used.
Hi Jimmy,About the buttonID actually even already included in view identifier, you still must manually added it to Android Layout, using this code in activity:
protected override int MenuLayoutId { get { return Resource.Layout.actionbarlistlayout; } }
actionbarlistlayout is the layout name, and inside of the axml:
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/SearchButton" android:icon="@drawable/ic_search" android:title="Search" android:showAsAction="ifRoom|withText|collapseActionView" android:actionViewClass="android.widget.SearchView" /> <item android:id="@+id/AddButton" android:icon="@drawable/ic_menu_add" android:title="Add" android:showAsAction="ifRoom|withText" /> </menu>
Can confirm i already tested it in MyInventoryWebApi which using DataListViewModelBase and Changing the Activity into Fragment and i encounter no problem the CanExecute function was working as intended (if i try to markSold marked Sold item, the button will be disabled)Best RegardArief
Clearly... there is something wrong here. Either that... or we're breaking some rules from Android's guidelines. Please take a look at MyInventory_MasterDetail that we modified. Specifically, adding a menu layout named "sold_actions.axml" and modified ItemListFragment.cs to specify MenuLayoutId. Please run the sample on Anroid Tablet for better viewing.
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/MarkSoldButton" android:title="@string/MarkAsSold" android:showAsAction="ifRoom|withText" /> </menu>
protected override int MenuLayoutId { get { return Resource.Menu.sold_actions; } }
Please download the solution by clicking here.
Hi Jimmy,Sorry looks like i send you the wrong code, (I assume the problem is from the lack of ID in axml) so it is actually already right to use ContextualActionBarSettings & EditingOptions, In your solution in MyInventory Master Detail what actually i change to allow the CanExecute to work is to change the CanExecuteMarkSold method in ItemListViewModel into:
private bool CanExecuteMarkSold(object parameter) { if (parameter is Item) return true; else if (parameter is IEnumerable<Item>) return ((IEnumerable<Item>)parameter).Where(o => o.IsSold == false).Count() > 0; return false; }
Here is the sample i make yesterday that similar with the solutions that you give me (using MyInventoryWebAPI)Please download the samples by clicking here.Hope that'll helpsBest RegardsArief
or
Choose this if you're already a member of Intersoft Community Forum. You can link your OpenID account to your existing Intersoft Social ID.
Choose this if you don't have an Intersoft account yet. Your authenticated OpenID will be automatically linked to your new Intersoft account.
Enter your Wordpress Blogname