コード例 #1
0
		private void Init(Model model) {
			this.DataContext = model;

			var applyCommand = new DelegateCommand(
				() => Success(new Result.Apply(model)),
				() => {
					if (repeatedPassword != model.password) {
						return false;
					}
					return true;
				}
			);
			OnRepeatedPasswordChanged += () => applyCommand.RaiseCanExecuteChanged();

			ApplyCommand = applyCommand;

			var cancelCommand = new DelegateCommand(
				() => Success(new Result.Cancel()),
				() => true
			);
			CancelCommand = cancelCommand;

			repeatedPassword = model.password;

			InitializeComponent();

			userNameCaption.CreateBinding(Label.ContentProperty, this.Strings, s => s.nameCaption);
			userNameValue.CreateBinding(TextBox.TextProperty, model, m => m.name);

			passwordCaption.CreateBinding(Label.ContentProperty, this.Strings, s => s.passwordCaption);
			repeatPasswordCaption.CreateBinding(Label.ContentProperty, this.Strings, s => s.repeatPasswordCaption);
			passwordValue.CreateBinding(
				TextBox.TextProperty, model,
				m => m.password,
				(m, v) => {
					m.password = String.IsNullOrEmpty(v) ? null : v;
					applyCommand.RaiseCanExecuteChanged();
				}
			);

			//repeatPasswordCaption.CreateBinding(Label.ContentProperty, this.Strings, s => s.repeatPassword);
			repeatPasswordValue.Text = repeatedPassword;
			repeatPasswordValue.TextChanged += (s, a) => {
				repeatedPassword = String.IsNullOrEmpty(repeatPasswordValue.Text) ? null : repeatPasswordValue.Text;
			};

			roleCaption.CreateBinding(Label.ContentProperty, this.Strings, s => s.roleCaption);
			roleValue.ItemsSource = EnumHelper.GetValues<UserLevel>().Where(v => v != UserLevel.anonymous && v != UserLevel.extended);
			roleValue.CreateBinding(ComboBox.SelectedValueProperty, model, m => m.level, (m, v) => m.level = v);

			applyButton.Command = ApplyCommand;
			applyButton.CreateBinding(Button.ContentProperty, SaveCancel, s => s.apply);

			cancelButton.Command = CancelCommand;
			cancelButton.CreateBinding(Button.ContentProperty, SaveCancel, s => s.cancel);

		}
コード例 #2
0
        public AddParticleDlgViewModel(IParticlesManager particleManager, Type targetType, IBlockManager blockManager)
        {
            _particleManager = particleManager;
            _blockManager = blockManager;
            AddParticleVm = new AddParticleViewViewModel(_particleManager, Visibility.Collapsed);
            OkCommand = new DelegateCommand<Window>((wnd) =>
            {
                if (AddParticleVm.UseNewParticle)
                {
                    var particle = _particleManager.CreateParticle(AddParticleVm.NewParticle.Material,
                        AddParticleVm.NewParticle.Begin, AddParticleVm.NewParticle.End);
                    _blockManager.AddParticleToBlock(_block, particle);
                }
                else if (AddParticleVm.UseExistParticle && AddParticleVm.ExistParticle.HasValue)
                {
                    var particle = _particleManager.GetParticleById(AddParticleVm.ExistParticle.Value);
                    _blockManager.AddParticleToBlock(_block, particle);
                }

                wnd.DialogResult = true;
                wnd.Close();
            }, wnd => _block != null && (AddParticleVm.UseNewParticle || AddParticleVm.UseExistParticle));

            SelectIdeaCommand = new DelegateCommand(() =>
            {
                var dlg = new SelectTagDlg(targetType);
                var res = dlg.ShowDialog();
                if (res.HasValue && res.Value && dlg.Id.HasValue)
                {
                    _block = _blockManager.GetBlockById(dlg.Id.Value);
                    BlockCaption = _block.Caption;
                    OkCommand.RaiseCanExecuteChanged();
                }
            });
        }
コード例 #3
0
        public DemoViewModel(IDemoProfileActivator demoListener)
        {
            _demoListener = demoListener;
            _activateIdentityCommand = new DelegateCommand(ActivateIdentity, IsIdentityValid);

            this.PropertyChanges(vm => vm.Identity).Subscribe(_ => _activateIdentityCommand.RaiseCanExecuteChanged());
        }
コード例 #4
0
 public void TestCanExecuteChanged2()
 {
     bool actioned1 = false;
     var command1 = new DelegateCommand(() => { });
     command1.CanExecuteChanged += (s, e) => actioned1 = true;
     command1.RaiseCanExecuteChanged();
     Assert.True(actioned1);
 }
コード例 #5
0
        public void CanExecuteChangedWithMultipleCommands()
        {
            var command1 = new DelegateCommand(() => { }, () => true);
            var command2 = new DelegateCommand<int>(i => { }, _ => true);

            var compositeCommand = new CompositeCommand();
            bool canExecuteEventFired = false;
            EventHandler eventHandler = (sender, eventArgs) =>
                                        {
                                            Assert.AreSame(compositeCommand, sender);
                                            Assert.IsNotNull(eventArgs);
                                            canExecuteEventFired = true;
                                        };
            compositeCommand.CanExecuteChanged += eventHandler;
            compositeCommand.RegisterCommand(command1);
            compositeCommand.RegisterCommand(command2);

            Assert.IsFalse(EventConsumer.EventCalled);

            command1.RaiseCanExecuteChanged();
            Assert.IsTrue(canExecuteEventFired);

            canExecuteEventFired = false;
            command2.RaiseCanExecuteChanged();
            Assert.IsTrue(canExecuteEventFired);

            canExecuteEventFired = false;
            compositeCommand.UnregisterCommand(command1);
            Assert.IsTrue(canExecuteEventFired);  // Unregister also raises CanExecuteChanged.

            canExecuteEventFired = false;
            command1.RaiseCanExecuteChanged();
            Assert.IsFalse(canExecuteEventFired);
            command2.RaiseCanExecuteChanged();
            Assert.IsTrue(canExecuteEventFired);

            canExecuteEventFired = false;
            compositeCommand.UnregisterCommand(command2);
            Assert.IsTrue(canExecuteEventFired);  // Unregister also raises CanExecuteChanged.

            canExecuteEventFired = false;
            command1.RaiseCanExecuteChanged();
            command2.RaiseCanExecuteChanged();
            Assert.IsFalse(canExecuteEventFired);
        }
コード例 #6
0
ファイル: PackageViewModel.cs プロジェクト: RobertiF/Dynamo
        public PackageViewModel(DynamoViewModel dynamoViewModel, Package model)
        {
            this.dynamoViewModel = dynamoViewModel;
            this.Model = model;

            ToggleTypesVisibleInManagerCommand = new DelegateCommand(ToggleTypesVisibleInManager, CanToggleTypesVisibleInManager);
            GetLatestVersionCommand = new DelegateCommand(GetLatestVersion, CanGetLatestVersion);
            PublishNewPackageVersionCommand = new DelegateCommand(PublishNewPackageVersion, CanPublishNewPackageVersion);
            PublishNewPackageCommand = new DelegateCommand(PublishNewPackage, CanPublishNewPackage);
            UninstallCommand = new DelegateCommand(Uninstall, CanUninstall);
            DeprecateCommand = new DelegateCommand(this.Deprecate, CanDeprecate);
            UndeprecateCommand = new DelegateCommand(this.Undeprecate, CanUndeprecate);

            this.dynamoViewModel.Model.NodeAdded += (node) => UninstallCommand.RaiseCanExecuteChanged();
            this.dynamoViewModel.Model.NodeDeleted += (node) => UninstallCommand.RaiseCanExecuteChanged();
            this.dynamoViewModel.Model.WorkspaceHidden += (ws) => UninstallCommand.RaiseCanExecuteChanged();
            this.dynamoViewModel.Model.Workspaces.CollectionChanged += (sender, args) => UninstallCommand.RaiseCanExecuteChanged();
        }
コード例 #7
0
        public void RaiseCanExecuteChanged_Fires_Event()
        {
            var command = new DelegateCommand(() => { });
            bool changedWasRaised = false;
            command.CanExecuteChanged += (s, e) => changedWasRaised = true;

            command.RaiseCanExecuteChanged();

            Assert.That(changedWasRaised);
        }
コード例 #8
0
ファイル: Package.cs プロジェクト: riteshchandawar/Dynamo
        public Package(string directory, string name, string versionName)
        {
            this.Loaded = false;
            this.RootDirectory = directory;
            this.Name = name;
            this.VersionName = versionName;
            this.LoadedTypes = new ObservableCollection<Type>();
            this.Dependencies = new ObservableCollection<PackageDependency>();
            this.LoadedCustomNodes = new ObservableCollection<CustomNodeInfo>();

            ToggleTypesVisibleInManagerCommand = new DelegateCommand(ToggleTypesVisibleInManager, CanToggleTypesVisibleInManager);
            GetLatestVersionCommand = new DelegateCommand(GetLatestVersion, CanGetLatestVersion);
            PublishNewPackageVersionCommand = new DelegateCommand(PublishNewPackageVersion, CanPublishNewPackageVersion);
            PublishNewPackageCommand = new DelegateCommand(PublishNewPackage, CanPublishNewPackage);
            UninstallCommand = new DelegateCommand(Uninstall, CanUninstall);
            DeprecateCommand = new DelegateCommand(this.Deprecate, CanDeprecate);
            UndeprecateCommand = new DelegateCommand(this.Undeprecate, CanUndeprecate);

            dynSettings.Controller.DynamoModel.NodeAdded += (node) => UninstallCommand.RaiseCanExecuteChanged();
            dynSettings.Controller.DynamoModel.NodeDeleted += (node) => UninstallCommand.RaiseCanExecuteChanged();
            dynSettings.Controller.DynamoModel.WorkspaceHidden += (ws) => UninstallCommand.RaiseCanExecuteChanged();
            dynSettings.Controller.DynamoModel.Workspaces.CollectionChanged += (sender, args) => UninstallCommand.RaiseCanExecuteChanged();
        }
コード例 #9
0
 public BluetoothSetupViewModel(IBluetoothService bluetoothService, IBluetoothProfileActivator bluetoothProfileActivator, ISchedulerProvider schedulerProvider)
 {
     _bluetoothService = bluetoothService;
     _bluetoothProfileActivator = bluetoothProfileActivator;
     _schedulerProvider = schedulerProvider;
     _roDevices = new ReadOnlyObservableCollection<IBluetoothDevice>(_devices);
     _scanForDevicesCommand = new DelegateCommand(ScanForDevices, CanScanForDevices);
     _status = ViewModelStatus.Error(Resources.Bluetooth_NoDevices_RequiresScan);
     _bluetoothProfileActivator.PropertyChanges(bs => bs.IsEnabled)
                      .Subscribe(_ =>
                                     {
                                         OnPropertyChanged("IsEnabled");
                                         _scanForDevicesCommand.RaiseCanExecuteChanged();
                                     });               
                          
 }
コード例 #10
0
ファイル: EditViewModelBase.cs プロジェクト: unicloud/FRP
 protected EditViewModelBase(IService service)
     : base(service)
 {
     _service = service;
     SaveCommand = new DelegateCommand<object>(OnSave, CanSave);
     AbortCommand = new DelegateCommand<object>(OnAbort, CanAbort);
     if (_service != null)
     {
         _service.PropertyChanged += (o, e) =>
         {
             if (!e.PropertyName.Equals("HasChanges", StringComparison.OrdinalIgnoreCase)) return;
             SaveCommand.RaiseCanExecuteChanged();
             AbortCommand.RaiseCanExecuteChanged();
         };
     }
 }
コード例 #11
0
        private void CommandsInit()
        {
            AddAddressCommand = new DelegateCommand(RaiseAddAddressRequest);
            EditAddressCommand = new DelegateCommand<Address>(RaiseEditAddressRequest);
            DeleteAddressCommand = new DelegateCommand(DeleteAddress);

            ShowAddEmailCommand = new DelegateCommand(ShowAddEmail);
            SaveNewEmailCommand = new DelegateCommand(SaveNewEmail, CanSaveNewEmail);
            DeleteEmailCommand = new DelegateCommand(DeleteEmail);
            CancelSaveEmailCommand = new DelegateCommand(CancelSaveEmail);

            ShowAddPhoneCommand = new DelegateCommand(ShowAddPhone);
            SaveNewPhoneCommand = new DelegateCommand(SaveNewPhone, CanSaveNewPhone);
            DeletePhoneCommand = new DelegateCommand(DeletePhone);
            CancelSavePhoneCommand = new DelegateCommand(CancelSavePhone);

            SaveNewEmailCommand.RaiseCanExecuteChanged();
            SaveNewPhoneCommand.RaiseCanExecuteChanged();
        }
コード例 #12
0
        public EventsViewModel()
        {
            SearchCommand = new DelegateCommand(Search, () => CanSearch);
            UndoFilterCommand = new DelegateCommand(UndoFilter, () => CanUndoFilter);

            //Get Distances
            DistanceOptions = new ObservableCollection<int>();
            GetDistanceOptions(false);

            //Get Page sizes
            PageSizeOptions = new ObservableCollection<int>();
            GetPageSizes(false);

            //Get Categories
            CategoryOptions = new ObservableCollection<Models.Category>();
            GetCategories(true);

            SearchResults = new ObservableCollection<Result>();
            SearchResults.CollectionChanged += (s, e) =>
                {
                    OnPropertyChanged("SearchResults");
                    UndoFilterCommand.RaiseCanExecuteChanged();
                };
        } 
コード例 #13
0
        public void ShouldUpdateEnabledStateIfCanExecuteChangedRaisesOnDelegateCommandAfterCollect()
        {
            var clickableObject = new MockClickableObject();
            var command = new DelegateCommand<object>(delegate { }, o => true);

            var behavior = new ButtonBaseClickCommandBehavior(clickableObject);
            behavior.Command = command;
            clickableObject.IsEnabled = false;

            GC.Collect();

            command.RaiseCanExecuteChanged();
            Assert.IsTrue(clickableObject.IsEnabled);
        }
コード例 #14
0
		private void Init(Model model) {
			OnCompleted += () => {
				disposables.Dispose();
			};
			this.DataContext = model;

			var userManagementEventArgs = activityContext.container.Resolve<IUserManagementEventArgs>();

			var createUserCommand = new DelegateCommand(
				() => Success(new Result.CreateUser(model)),
				() => true
			);
			var deleteUserCommand = new DelegateCommand(
				() => Success(new Result.DeleteUser(model)),
				() => model.selection != null
			);
			var modifyUserCommand = new DelegateCommand(
				() => Success(new Result.ModifyUser(model)),
				() => model.selection != null
			);
			disposables.Add(
				model
					.GetPropertyChangedEvents(m => m.selection)
					.Subscribe(v => {
						modifyUserCommand.RaiseCanExecuteChanged();
						deleteUserCommand.RaiseCanExecuteChanged();
					})
			);
			var downloadPoliciesCommand = new DelegateCommand(
				() => {
					var dlg = new SaveFileDialog();
					dlg.FileName = userManagementEventArgs.Manufacturer + "-" + userManagementEventArgs.DeviceModel + "-policies.txt";
					dlg.Filter = "Text files (*.txt) |*.txt|All files (*.*)|*.*";
					if (dlg.ShowDialog() == true) {
						Success(new Result.DownloadPolicy(model, dlg.FileName));
					}
				},
				() => true
			);
			var uploadPoliciesCommand = new DelegateCommand(
				() => {
					var dlg = new OpenFileDialog();
					if (dlg.ShowDialog() == true) {
						Success(new Result.UploadPolicy(model, dlg.FileName));
					}
				},
				() => true
			);
			InitializeComponent();

			Localization();

			usersList.ItemsSource = model.users;
			usersList.CreateBinding(
				ListBox.SelectedValueProperty, model,
				m => m.selection,
				(m, v) => m.selection = v
			);
			createUserButton.Command = createUserCommand;
			modifyUserButton.Command = modifyUserCommand;
			deleteUserButton.Command = deleteUserCommand;
			uploadPoliciesButton.Command = uploadPoliciesCommand;
			downloadPoliciesButton.Command = downloadPoliciesCommand;
		}
コード例 #15
0
        protected void InitializeCommands()
        {
            OpenItemCommand = new DelegateCommand(RiseOpenItemCommand);
            MinimizeCommand = new DelegateCommand(() => MinimizableViewRequestedEvent(this, null));

            SaveChangesCommand = new DelegateCommand<object>(RaiseSaveInteractionRequest, x => IsValid);
            CancelCommand = new DelegateCommand<object>(RaiseCancelInteractionRequest);
            CancelConfirmRequest = new InteractionRequest<Confirmation>();
            SaveConfirmRequest = new InteractionRequest<Confirmation>();

            ResolveAndSaveCommand = new DelegateCommand<object>(RaiseResolveAndSaveInteractionRequest,
                                                                (x) => CanRaiseResolveAndSaveChangedInteractionRequest());
            ProcessAndSaveCommand = new DelegateCommand<object>(RaiseProcessAndSaveInteractionRequest,
                                                                (x) => CanRaiseProcessAndSaveInteractionRequest());
            ResolveAndSaveCommand.RaiseCanExecuteChanged();
            ProcessAndSaveCommand.RaiseCanExecuteChanged();

            OpenCaseCommand = new DelegateCommand<Case>(RiseOpenCaseInteractionRequest,
                                                        x => x != null && x.CaseId != InnerItem.CaseId);

            SwitchContactNameEditModeCommand = new DelegateCommand(SwitchContactNameEditMode);


            CreateNewCaseForCurrentContactCommand = new DelegateCommand(CreateNewCaseForCurrentContact);
            DeleteCurrentContactCommand = new DelegateCommand(DeleteCurrentContact, () => _authContext.CheckPermission(PredefinedPermissions.CustomersDeleteCustomer));

            CreateCustomerInteractionRequest = new InteractionRequest<ConditionalConfirmation>();
            CommonInfoRequest = new InteractionRequest<ConditionalConfirmation>();

            DisplayNameUpdateCommand = new DelegateCommand(DisplayNameUpdate);

            RefreshContactOrdersPanelCommand = new DelegateCommand(RefreshContactOrdersPanel);
            LoadCompletedCommand = new DelegateCommand(LoadCompleted);

            DeleteCaseCommand = new DelegateCommand<string>(DeleteCase);
        }
コード例 #16
0
		private void Init(Model model) {
			this.DataContext = model;

			var applyCommand = new DelegateCommand(
				() => Success(new Result.Apply(userName, password, userLevel)),
				() => {
					if (repeatedPassword != password) {
						return false;
					}
					if (String.IsNullOrWhiteSpace(userName)) {
						return false;
					}
					if (model.existingUsers != null && model.existingUsers.Contains(userName)) {
						return false;
					}
					return true;
				}
			);
			OnRepeatedPasswordChanged += () => applyCommand.RaiseCanExecuteChanged();
			OnPasswordChanged += () => applyCommand.RaiseCanExecuteChanged();
			OnUserNameChanged += () => applyCommand.RaiseCanExecuteChanged();
			
			ApplyCommand = applyCommand;
			
			var cancelCommand = new DelegateCommand(
				() => Success(new Result.Cancel()),
				() => true
			);
			CancelCommand = cancelCommand;

			password = model.defaultPassword;
			repeatedPassword = model.defaultPassword;
			userName = model.defaultUserName;
			userLevel = model.defaultUserLevel;

			InitializeComponent();

            userNameCaption.CreateBinding(Label.ContentProperty, this.Strings, s => s.nameCaption);
			userNameValue.Text = userName;
			userNameValue.TextChanged += (s, a) => userName = userNameValue.Text;

            passwordCaption.CreateBinding(Label.ContentProperty, this.Strings, s => s.passwordCaption);
			passwordValue.Text = password;
			passwordValue.TextChanged +=
				(s, a) => password = String.IsNullOrEmpty(passwordValue.Text) ? null : passwordValue.Text;

			//repeatPasswordCaption.CreateBinding(Label.ContentProperty, this.Strings, s => s.repeatPassword);
			repeatPasswordValue.Text = repeatedPassword;
			repeatPasswordValue.TextChanged +=
				(s, a) => repeatedPassword = String.IsNullOrEmpty(repeatPasswordValue.Text) ? null : repeatPasswordValue.Text;

			roleCaption.CreateBinding(Label.ContentProperty, this.Strings, s => s.roleCaption);
			roleValue.ItemsSource = EnumHelper.GetValues<UserLevel>().Where(v=>v!= UserLevel.anonymous && v!=UserLevel.extended);
			roleValue.SelectedValue = userLevel;
			roleValue.SelectionChanged += (s, a) => userLevel = (UserLevel)roleValue.SelectedValue;

			applyButton.Command = ApplyCommand;
			applyButton.CreateBinding(Button.ContentProperty, SaveCancel, s => s.apply);

			cancelButton.Command = CancelCommand;
			cancelButton.CreateBinding(Button.ContentProperty, SaveCancel, s => s.cancel);

		}
コード例 #17
0
        public void CanExecuteChangedEventShouldBeWeak()
        {
            var command1 = new DelegateCommand(() => { }, null);
            var command2 = new DelegateCommand<int>(i => { }, null);

            var compositeCommand = new CompositeCommand();
            compositeCommand.RegisterCommand(command1);
            compositeCommand.RegisterCommand(command2);
            compositeCommand.CanExecuteChanged += new EventConsumer().EventHandler;

            // Garbage collect the EventConsumer.
            GC.Collect();

            EventConsumer.Clear();
            command1.RaiseCanExecuteChanged();
            command2.RaiseCanExecuteChanged();
            Assert.IsFalse(EventConsumer.EventCalled);
        }