Example #1
0
 protected ConversationViewModel(Func <Command, bool> commandHandler, IMessageManager messageManager) : base(commandHandler)
 {
     this.messageManager = messageManager;
     SendCommand         = new MvxCommand(OnSend, () => CanSendMessage && !string.IsNullOrEmpty(EnteredText));
     messageManager.CanSendMessagesChanged += () => {
         SendCommand.RaiseCanExecuteChanged();
         RaisePropertyChanged(nameof(CanSendMessage));
     };
     TogglePinCommand = new MvxCommand(() => {
         SetPinned(!IsPinned);
         IsPinned = !IsPinned;
     });
 }
        public MapPageViewModel(IMvxNavigationService navigationService, IPlacesStorage placesStorage)
        {
            _navigationService     = navigationService;
            PlacesStorage          = placesStorage;
            SearchAddressesCommand = new MvxCommand(SearchAddresses, CanNavigateToAddressesPage);
            IsInternetAccessible   = Connectivity.NetworkAccess == NetworkAccess.Internet;

            Connectivity.ConnectivityChanged += (sender, e) =>
            {
                IsInternetAccessible = e.NetworkAccess == NetworkAccess.Internet;
                SearchAddressesCommand.RaiseCanExecuteChanged();
            };
        }
Example #3
0
        private void Validate()
        {
            bool hasErrorBefore = HasErrors;

            _parameterError = _originalParameter == Parameter ||
                              string.IsNullOrEmpty(_originalParameter) && string.IsNullOrEmpty(Parameter)
                ? "Change parameter before update"
                : null;

            _applyCommand.RaiseCanExecuteChanged();
            if (hasErrorBefore != HasErrors)
            {
                var handler = ErrorsChanged;
                if (handler != null)
                {
                    handler(this, new DataErrorsChangedEventArgs("Parameter"));
                }
            }
        }
        public void CanExecuteChanged()
        {
            var canExecute = false;

            var command = new MvxCommand(() => { }, () => canExecute);

            Assert.False(command.CanExecute());

            var i = 0;

            command.CanExecuteChanged += (s, e) =>
            {
                i++;
            };

            canExecute = true;
            command.RaiseCanExecuteChanged();

            Assert.True(command.CanExecute());
            Assert.Equal(1, i);
        }