locked
The event 'System.Windows.Input.ICommand.CanExecuteChanged' can only appear on the left hand side of += or -=

    Question

  • ViewModel

    /// <summary> /// Gets or sets the SelectImageCommand. /// </summary> public ICommand SelectImageCommand { get; private set; } private async void ExecuteSelcetImageCommand() { try { Event.ImageFilePath = await _webCamService.CaptureImageAsync(); Event.HasImage = !string.IsNullOrEmpty(Event.ImageFilePath); } catch (Exception ex) { ex.Message.ToString(); _messageBoxService.ShowAsync("There was a problem capturing the image", "Warning"); } } /// <summary> /// Gets or sets the CaptureImageCommand. /// </summary> public ICommand CaptureImageCommand { get; private set; } private async void ExecuteCaptureImageCommand()// (object parameter) { try { Event.ImageFilePath = await _webCamService.CaptureImageAsync(); Event.HasImage = !string.IsNullOrEmpty(Event.ImageFilePath); } catch (Exception ex) { ex.Message.ToString(); _messageBoxService.ShowAsync("There was a problem capturing the image","Warning"); } }

    The event 'System.Windows.Input.ICommand.CanExecuteChanged' can only appear on the left hand side of += or -=

     public async Task SaveEventAsync()
            {
                if (Event != null &&  (Event.EventPlace !=null)  && (Event.EventDateTime != null ) && ( Event.EventName != null ))
                {
                        SelectImageCommand.CanExecuteChanged();
                        CaptureImageCommand.CanExecuteChanged();
                        GetEventLocationCommand.CanExecuteChanged();
                    
                    Event.AddedDateTime = DateTime.UtcNow;
                    await _dataService.SaveEventsAsync(Event);
                    _navigationService.GoBack();
                }
            }

    Model

       ///// <summary>
            ///// The ImagePath
            ///// </summary>
            private string _imageFilePath;
            ///// <summary>
            ///// Gets or sets the ImagePath.
            ///// </summary>
            public string ImageFilePath
            {
                get 
                { 
                    return _imageFilePath;
                }
                set 
                { 
                    Set("ImageFilePath",ref _imageFilePath, value);
                }
            }
    
            ///// <summary>
            ///// The hasImage
            ///// </summary>
            private bool _hasImage = false;
            ///// <summary>
            ///// Gets or sets the hasImage.
            ///// </summary>
            public bool HasImage
            {
                get 
                { 
                    return _hasImage; 
                }
                set 
                {
                    Set("HasImage",ref _hasImage, value);
                }
            }

    Tuesday, October 7, 2014 12:48 PM

Answers

  • SelectImageCommand.CanExecuteChanged is an Event. You can only subscribe to an event to be informed of certain things happening (in this case the value of the CanExecute flag changing).

    You are however trying to call it like a method. If you can't directly set CanExecute you will have to override it in your implementations of those commands so you can change it accordingly.

    Tuesday, October 7, 2014 1:00 PM