Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CanExecute not firing on OnCanExecuteChanged() #7

Closed
ksachdeva opened this issue Oct 7, 2016 · 3 comments
Closed

CanExecute not firing on OnCanExecuteChanged() #7

ksachdeva opened this issue Oct 7, 2016 · 3 comments
Assignees

Comments

@ksachdeva
Copy link

Hi Stephen,

I tried the AsyncCommand in a Xamarin Forms project and saw strange behavior.

  • I do supply the CanExecute to the AsyncCommand constructor
  • I can see that it does get invoked once
  • When my properties in the ViewModel change I invoke OnCanExecuteChanged()

Problem :
I expected my canExecute delegate to be invoked but it does not.

I read the source code of AsyncCommand and then traversed up the chain in Mvvm.Core to see the implementation of WeakCanExecuteChanged. Everything looks fine.

I then copied your AsyncCommand implementation locally, renamed it but still kept the same implementation i.e. it relies on WeakCanExecuteChanged from Mvvm.Core. The behavior was still the same.

I then copied your WeakCanExecuteChanged implementation locally, renamed it and used it with AsyncCommand. Still the same behavior. Since now I could debug I can see that OnCanExecuteChanged in WeakCanExecuteChanged is never being invoked.

I then replaced the WeakCollection with a List (essentially not using WeakReferences at all) and then it seemed to work.

I know that the RelayCommand implementation of MvvmLight uses the similar technique of using WeakReference and it does work (it is what I am trying to replace in my relatively larger project with AsyncCommand after reading your excellent articles).

Any suggestions.

Regards & thanks
Kapil

@StephenCleary StephenCleary self-assigned this Oct 8, 2016
@StephenCleary
Copy link
Owner

It looks like the same problem as this bug.

@StephenCleary
Copy link
Owner

And this one.

It appears as though different platforms (specifically Xamarin) have ignored the special behavior of CanExecuteChanged, instead deciding to treat it like any other event. I'm undecided as to whether this is "right" or "wrong" for Xamarin to do (arguably, the special behavior is only due to a bug in WPF kept for backcompat reasons).

Regardless, it looks like the only proper fix is to have an implementation toggle at the application level. Since my library doesn't (and won't) use platform enlightenments, it'll have to be done in code. I will, however, default to the implementation that works for Xamarin and breaks WPF.

@StephenCleary
Copy link
Owner

Fixed in 1.0.0-eta-05

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants