Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

ICommand CanExecute not called

$
0
0

Hi, I have this scenario (I simplified the logic just to this sample):
in xaml
<Button x:Name="btnLoad" Text="Load" Command="{Binding LoadScanpackCommand}" CommandParameter="{Binding ScanpackHdr}" />

in view model

this.LoadScanpackCommand = new Command<ScanpackHdr> ( (scanpack) => { System.Diagnostics.Debug.WriteLine ("LoadScanpackCommand - {0} - {1}", scanpack.ProdNo, scanpack.PackageNo); }, (scanpack) => { System.Diagnostics.Debug.WriteLine ("LoadScanpackCommand enable called"); return true; });

` private ScanpackHdr scanpackHdr;
public const string ScanpackHdrPropertyName = "ScanpackHdr";

    public ScanpackHdr ScanpackHdr 
    {
        get { return scanpackHdr; }
        set { SetProperty (ref scanpackHdr, value, ScanpackHdrPropertyName);}

    }`

Everything works fine if I use string or int as command parameter but it is not working using a custom class (ScanpackHdr);
This class ScanpackHdr implements INotifyPropertyChanged and I am doing in viewmodel:

        scanpackHdr.PropertyChanged += (sender, e) => {
            OnPropertyChanged("ScanpackHdr");
        };

and this gets called but it never calls CanExecute after that, any idea? When is CanExecuted called? I thought it got called when the binding parameter changed.

Thanks.


Viewing all articles
Browse latest Browse all 77050

Trending Articles