当前位置: 首页>>代码示例>>C#>>正文


C# DelegateCommand.RaiseCanExecuteChanged方法代码示例

本文整理汇总了C#中DelegateCommand.RaiseCanExecuteChanged方法的典型用法代码示例。如果您正苦于以下问题:C# DelegateCommand.RaiseCanExecuteChanged方法的具体用法?C# DelegateCommand.RaiseCanExecuteChanged怎么用?C# DelegateCommand.RaiseCanExecuteChanged使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DelegateCommand的用法示例。


在下文中一共展示了DelegateCommand.RaiseCanExecuteChanged方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Execute

        private bool _windowClosedBySelf = false; // Tracks whether the window was closed by logic internal
                                                  // to the command (e.g. not by clicking the window's close button)
        // Presents the user with a sign-in dialog
        public override void Execute(object parameter)
        {
            // Initialize the viewmodel if not yet done
            if (viewModel == null)
            {
                // Instantiate the viewmodel and sign-in/cancel commands
                viewModel = new SignInViewModel();
                DelegateCommand signInCommand = new DelegateCommand(onSignIn, canSignIn);
                viewModel.SignIn = signInCommand;
                viewModel.Cancel = new DelegateCommand(onCancel);

                // When a property changes on the viewmodel, have the sign-in command check its executable state
                viewModel.PropertyChanged += (o, e) => signInCommand.RaiseCanExecuteChanged();

                // instantiate the view
                view = new SignInView() { Margin = new Thickness(10) };

                // plug the viewmodel into the view
                view.DataContext = viewModel;
            }

            // Prompt for sign-in
            if (MapApplication.Current != null)
                MapApplication.Current.ShowWindow(Strings.SignIn, view, true, null, onWindowClosed,
                    WindowType.DesignTimeFloating);
        }
开发者ID:yulifengwx,项目名称:arcgis-viewer-silverlight,代码行数:29,代码来源:SignInCommand.cs

示例2: MultiViewModel

 public MultiViewModel()
 {
     SelectAllCommand = new DelegateCommand(SelectAll);
     ClearSelectionCommand = new DelegateCommand(ClearSelection, CanClearSelection);
     SelectedItems = new ObservableCollection<ItemViewModel>();
     SelectedItems.CollectionChanged += (sender, args) => ClearSelectionCommand.RaiseCanExecuteChanged();
 }
开发者ID:Slesa,项目名称:Playground,代码行数:7,代码来源:MultiViewModel.cs

示例3: CommandCanExecuteChangedTest

        public void CommandCanExecuteChangedTest()
        {
            DelegateCommand command = new DelegateCommand(() => { });

            AssertHelper.CanExecuteChangedEvent(command, () => command.RaiseCanExecuteChanged());

            AssertHelper.ExpectedException<ArgumentNullException>(
                () => AssertHelper.CanExecuteChangedEvent(null, () => command.RaiseCanExecuteChanged()));
            AssertHelper.ExpectedException<ArgumentNullException>(
                () => AssertHelper.CanExecuteChangedEvent(command, null));

            AssertHelper.ExpectedException<AssertException>(() =>
                AssertHelper.CanExecuteChangedEvent(command, () => { }));

            AssertHelper.ExpectedException<AssertException>(() =>
                AssertHelper.CanExecuteChangedEvent(command, () =>
                {
                    command.RaiseCanExecuteChanged();
                    command.RaiseCanExecuteChanged();
                }));
        }
开发者ID:Kayomani,项目名称:FAP,代码行数:21,代码来源:CanExecuteChangedEventTest.cs

示例4: MainViewModel

        public MainViewModel(NumberDiceViewModel numDiceViewModel,
            NumberSidesViewModel numSidesViewModel,
            RollModeViewModel rollModeViewModel,
            RandomModeViewModel randomModeViewModel)
        {
            if (numDiceViewModel == null)
                throw new ArgumentNullException("numDiceViewModel is null.");
            if (numSidesViewModel == null)
                throw new ArgumentNullException("numSidesViewModel is null.");
            if (rollModeViewModel == null)
                throw new ArgumentNullException("rollModeViewModel is null.");
            if (randomModeViewModel == null)
                throw new ArgumentNullException("randomModeViewModel is null.");

            SetupPages = new ObservableCollection<IPageViewModel>();
            Dice = new ObservableCollection<IDieViewModel>();
            Statistics = new ObservableCollection<IStatisticViewModel>();
            _rollCommand = new DelegateCommand(x => randomModeViewModel.GeneratorIsReady, x => rollDice());

            _numDiceViewModel = numDiceViewModel;
            _numDiceViewModel.NumberDiceChanged += (sender, e) => onSetupChanged();
            SetupPages.Add(_numDiceViewModel);

            _numSidesViewModel = numSidesViewModel;
            _numSidesViewModel.NumberSidesChanged += (sender, e) => onSetupChanged();
            SetupPages.Add(_numSidesViewModel);

            _rollModeViewModel = rollModeViewModel;
            _rollModeViewModel.ModeChanged += (sender, e) => onSetupChanged();
            SetupPages.Add(_rollModeViewModel);

            _randomModeViewModel = randomModeViewModel;
            _randomModeViewModel.RandomModeChanged += (sender, e) => onSetupChanged();
            _randomModeViewModel.Ready += (sender, e) => _rollCommand.RaiseCanExecuteChanged();
            _randomModeViewModel.Error += (sender, e) => _rollCommand.RaiseCanExecuteChanged();
            // TODO: Add error checking before adding this feature
            //SetupPages.Add(_randomModeViewModel);

            onSetupChanged();
        }
开发者ID:pcrockett,项目名称:Dice,代码行数:40,代码来源:MainViewModel.cs

示例5: CommandCanExecuteChangedTest2

        public void CommandCanExecuteChangedTest2()
        {
            var command = new DelegateCommand(() => { });
            
            AssertHelper.ExpectedException<AssertException>(() =>
                AssertHelper.CanExecuteChangedEvent(command, () => { }));

            AssertHelper.ExpectedException<AssertException>(() =>
                AssertHelper.CanExecuteChangedEvent(command, () =>
                {
                    command.RaiseCanExecuteChanged();
                    command.RaiseCanExecuteChanged();
                }));

            
            AssertHelper.ExpectedException<AssertException>(() =>
                AssertHelper.CanExecuteChangedEvent(command, () => command.RaiseCanExecuteChanged(), 0, ExpectedChangedCountMode.Exact));

            AssertHelper.ExpectedException<AssertException>(() =>
                AssertHelper.CanExecuteChangedEvent(command, () => command.RaiseCanExecuteChanged(), 2, ExpectedChangedCountMode.Exact));

            AssertHelper.ExpectedException<AssertException>(() =>
                AssertHelper.CanExecuteChangedEvent(command, () => command.RaiseCanExecuteChanged(), 2, ExpectedChangedCountMode.AtLeast));

            AssertHelper.ExpectedException<AssertException>(() =>
                AssertHelper.CanExecuteChangedEvent(command, () => command.RaiseCanExecuteChanged(), 0, ExpectedChangedCountMode.AtMost));
        }
开发者ID:jbe2277,项目名称:waf,代码行数:27,代码来源:CanExecuteChangedEventTest.cs

示例6: RaiseCanExecuteChangedTest

        public void RaiseCanExecuteChangedTest()
        {
            bool executed = false;
            bool canExecute = false;
            DelegateCommand command = new DelegateCommand(() => executed = true, () => canExecute);

            Assert.IsFalse(command.CanExecute());
            canExecute = true;
            Assert.IsTrue(command.CanExecute());

            AssertHelper.CanExecuteChangedEvent(command, () => command.RaiseCanExecuteChanged());

            Assert.IsFalse(executed);
        }
开发者ID:BigEgg,项目名称:Core,代码行数:14,代码来源:DelegateCommandTest.cs

示例7: PersonEntryViewModel

        public PersonEntryViewModel(IPersonEntry person, ISchedulerProvider schedulerProvider)
        {
            _person = person;
            _schedulerProvider = schedulerProvider;

            SaveCommand = new DelegateCommand(Save, () => !Person.HasErrors && !Person.State.HasError);

            var errors = Observable.FromEventPattern<EventHandler<DataErrorsChangedEventArgs>, DataErrorsChangedEventArgs>(
                    h => Person.ErrorsChanged += h,
                    h => Person.ErrorsChanged -= h)
                .Select(_ => Unit.Default);
            var states = Person.OnPropertyChanges(p => p.State)
                               .Select(_ => Unit.Default);

            _errorStateSubscription = Observable
                .Merge(errors, states)
                .ObserveOn(_schedulerProvider.Dispatcher)
                .Subscribe(_ => SaveCommand.RaiseCanExecuteChanged());

            states.ObserveOn(_schedulerProvider.Dispatcher)
                 .Subscribe(_ => OnPropertyChanged("State"));
        }
开发者ID:LeeCampbell,项目名称:DDDMVVM,代码行数:22,代码来源:PersonEntryViewModel.cs

示例8: CommandCanExecuteChangedTest1

        public void CommandCanExecuteChangedTest1()
        {
            var command = new DelegateCommand(() => { });

            AssertHelper.CanExecuteChangedEvent(command, () => command.RaiseCanExecuteChanged());
            AssertHelper.CanExecuteChangedEvent(command, () => command.RaiseCanExecuteChanged(), 1, ExpectedChangedCountMode.Exact);
            AssertHelper.CanExecuteChangedEvent(command, () => command.RaiseCanExecuteChanged(), 0, ExpectedChangedCountMode.AtLeast);
            AssertHelper.CanExecuteChangedEvent(command, () => command.RaiseCanExecuteChanged(), 2, ExpectedChangedCountMode.AtMost);


            AssertHelper.ExpectedException<ArgumentNullException>(
                () => AssertHelper.CanExecuteChangedEvent(null, () => command.RaiseCanExecuteChanged()));
            
            AssertHelper.ExpectedException<ArgumentNullException>(
                () => AssertHelper.CanExecuteChangedEvent(command, null));

            AssertHelper.ExpectedException<ArgumentOutOfRangeException>(
                () => AssertHelper.CanExecuteChangedEvent(command, () => command.RaiseCanExecuteChanged(), -1, ExpectedChangedCountMode.Exact));
        }
开发者ID:jbe2277,项目名称:waf,代码行数:19,代码来源:CanExecuteChangedEventTest.cs

示例9: OnLoggedIn

        void OnLoggedIn(dynamic result)
        {
            if (result["Result"].ToObject<bool>())
            {
                m_ServerStatusMetadataSource = result["ServerMetadataSource"].ToObject<List<KeyValuePair<string, StatusInfoAttribute[]>>>();

                BuildGridColumns(
                    m_ServerStatusMetadataSource.FirstOrDefault(p => string.IsNullOrEmpty(p.Key)).Value,
                    GetCommonColumns(m_ServerStatusMetadataSource.Where(p => !string.IsNullOrEmpty(p.Key)).Select(c => c.Value).ToArray()));

                var nodeInfo = DynamicViewModelFactory.Create(result["NodeStatus"].ToString());

                GlobalInfo = nodeInfo.BootstrapStatus;

                var instances = nodeInfo.InstancesStatus as IEnumerable<DynamicViewModel.DynamicViewModel>;
                Instances = new ObservableCollection<DynamicViewModel.DynamicViewModel>(instances.Select(i =>
                    {
                        var startCommand = new DelegateCommand<DynamicViewModel.DynamicViewModel>(ExecuteStartCommand, CanExecuteStartCommand);
                        var stopCommand = new DelegateCommand<DynamicViewModel.DynamicViewModel>(ExecuteStopCommand, CanExecuteStopCommand);
                        var restartCommand = new DelegateCommand<DynamicViewModel.DynamicViewModel>(ExecuteRestartCommand, CanExecuteRestartCommand);

                        i.PropertyChanged += (s, e) =>
                            {
                                if (string.IsNullOrEmpty(e.PropertyName)
                                    || e.PropertyName.Equals("IsRunning", StringComparison.OrdinalIgnoreCase))
                                {
                                    startCommand.RaiseCanExecuteChanged();
                                    stopCommand.RaiseCanExecuteChanged();
                                    restartCommand.RaiseCanExecuteChanged();
                                }
                            };

                        i.Set("StartCommand", startCommand);
                        i.Set("StopCommand", stopCommand);
                        i.Set("RestartCommand", restartCommand);

                        return i;
                    }));
                State = NodeState.Connected;
                LastUpdatedTime = DateTime.Now;
            }
            else
            {
                m_LoginFailed = true;
                //login failed
                m_WebSocket.Close();
                ErrorMessage = "Logged in failed!";
            }
        }
开发者ID:huamanhtuyen,项目名称:TagLo2,代码行数:49,代码来源:NodeMasterViewModel.cs


注:本文中的DelegateCommand.RaiseCanExecuteChanged方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。