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


C# RelayCommand.RaiseCanExecuteChanged方法代码示例

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


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

示例1: CanExecuteChangedTest

        public void CanExecuteChangedTest()
        {
            var command = new RelayCommand(() =>
            {
            },
                                           () => true);

            var canExecuteChangedCalled = 0;

            var canExecuteChangedEventHandler = new EventHandler((s, e) => canExecuteChangedCalled++);

            command.CanExecuteChanged += canExecuteChangedEventHandler;

            command.RaiseCanExecuteChanged(true);

#if SILVERLIGHT
            Assert.AreEqual(1, canExecuteChangedCalled);
#else
            // In WPF, cannot trigger the CanExecuteChanged event like this
            Assert.AreEqual(0, canExecuteChangedCalled);
#endif

            command.CanExecuteChanged -= canExecuteChangedEventHandler;
            command.RaiseCanExecuteChanged(true);

#if SILVERLIGHT
            Assert.AreEqual(1, canExecuteChangedCalled);
#else
            // In WPF, cannot trigger the CanExecuteChanged event like this
            Assert.AreEqual(0, canExecuteChangedCalled);
#endif
        }
开发者ID:ssickles,项目名称:archive,代码行数:32,代码来源:RelayCommandTest.cs

示例2: RegisterPropertyChanged

 public void RegisterPropertyChanged(RelayCommand command)
 {
     _target.PropertyChanged += (sender, args) =>
     {
         if (_dependentPropertyNames.Contains(args.PropertyName))
         {
             command.RaiseCanExecuteChanged();
         }
     };
 }
开发者ID:LodewijkSioen,项目名称:SensorCoreExport,代码行数:10,代码来源:DependentRelayCommand.cs

示例3: TestCanExecuteChanged

        public void TestCanExecuteChanged()
        {
            var command = new RelayCommand<string>(
                p =>
                {
                },
                p => true);

            var canExecuteChangedCalled = 0;

            var canExecuteChangedEventHandler = new EventHandler((s, e) => canExecuteChangedCalled++);

            command.CanExecuteChanged += canExecuteChangedEventHandler;

            command.RaiseCanExecuteChanged();

#if SILVERLIGHT
             Assert.AreEqual(1, canExecuteChangedCalled);
#elif NETFX_CORE
            Assert.AreEqual(1, canExecuteChangedCalled);
#elif PORTABLE
            Assert.AreEqual(1, canExecuteChangedCalled);
#else
            // In WPF, cannot trigger the CanExecuteChanged event like this
            Assert.AreEqual(0, canExecuteChangedCalled);
#endif

            command.CanExecuteChanged -= canExecuteChangedEventHandler;

            command.RaiseCanExecuteChanged();

#if SILVERLIGHT
             Assert.AreEqual(1, canExecuteChangedCalled);
#elif NETFX_CORE
            Assert.AreEqual(1, canExecuteChangedCalled);
#elif PORTABLE
            Assert.AreEqual(1, canExecuteChangedCalled);
#else
            // In WPF, cannot trigger the CanExecuteChanged event like this
            Assert.AreEqual(0, canExecuteChangedCalled);
#endif
        }
开发者ID:dbremner,项目名称:mvvmlight,代码行数:42,代码来源:RelayCommandGenericTest.cs

示例4: MainWindowViewModel

 public MainWindowViewModel()
 {
     SearchCommand = new RelayCommand(() => OnSearchExecuted(), () => !string.IsNullOrWhiteSpace(_searchText));
     ClearCommand = new RelayCommand(() => SeriesCollection.Clear(), () => SeriesCollection.Count > 0);
     SerializeCommand = new RelayCommand(OnSerializeExecuted, () => SeriesCollection.Count > 0);
     SeriesCollection.CollectionChanged += (s, e) =>
     {
         ClearCommand.RaiseCanExecuteChanged();
         SerializeCommand.RaiseCanExecuteChanged();
     };
 }
开发者ID:StuartMeeks,项目名称:TheTVDBSharp,代码行数:11,代码来源:MainWindowViewModel.cs

示例5: TestCanExecuteChanged

        public void TestCanExecuteChanged()
        {
            var command = new RelayCommand(() =>
            {
            },
                                           () => true);

            var canExecuteChangedCalled = 0;

            var canExecuteChangedEventHandler = new EventHandler((s, e) => canExecuteChangedCalled++);

            command.CanExecuteChanged += canExecuteChangedEventHandler;

            command.RaiseCanExecuteChanged();

            Assert.AreEqual(1, canExecuteChangedCalled);

            command.CanExecuteChanged -= canExecuteChangedEventHandler;
            command.RaiseCanExecuteChanged();

            Assert.AreEqual(1, canExecuteChangedCalled);
        }
开发者ID:lavige777,项目名称:GalaSoft.MvvmLight,代码行数:22,代码来源:RelayCommandTest.cs

示例6: MainViewModel

        public MainViewModel(IMessageBoxService messageBoxService)
        {
            _messageBoxService = messageBoxService;

            AddItemCommand = new RelayCommand(() =>
            {
                Items.Add(DateTime.Now.ToString());

                EnableSelectionCommand.RaiseCanExecuteChanged();
            });

            EnableSelectionCommand = new RelayCommand(() =>
            {
                IsSelectionEnabled = true;
            }, () => Items.Count > 0);

            DeleteItemsCommand = new RelayCommand<System.Collections.IList>(items =>
            {
                var itemsToRemove = items
                    .Cast<string>()
                    .ToArray();

                foreach (var itemToRemove in itemsToRemove)
                {
                    Items.Remove(itemToRemove);
                }

                EnableSelectionCommand.RaiseCanExecuteChanged();

                IsSelectionEnabled = false;
            });

            BackKeyPressCommand = new RelayCommand<CancelEventArgs>(e =>
            {
                if (IsSelectionEnabled)
                {
                    IsSelectionEnabled = false;

                    e.Cancel = true;
                }
            });

            AboutCommand = new RelayCommand(() =>
            {
                _messageBoxService.Show("Cimbalino Windows Phone Toolkit Bindable Application Bar Sample", "About");
            });

            Items = new ObservableCollection<string>();
        }
开发者ID:Cimbalino,项目名称:Cimbalino-Phone-Toolkit,代码行数:49,代码来源:MainViewModel.cs

示例7: CreateNewPlaylist

        //create a dialog that accepts a playlist name and returns the new playlist
        public async Task<Playlist> CreateNewPlaylist()
        {
            Playlist play = new Playlist { PlaylistId = Guid.NewGuid() };
            var dialog = new ContentDialog()
            {
                Title = "New Playlist",
            };
            var panel = new StackPanel();
            var tb = new TextBox
            {
                PlaceholderText = "Enter the new playlist's name",
                Margin = new Windows.UI.Xaml.Thickness { Top = 10 }
            };
            panel.Children.Add(tb);
            dialog.Content = panel;

            dialog.PrimaryButtonText = "Save";
            var cmd = new RelayCommand(() =>
            {
                play.PlaylistName = tb.Text;
                
            }, () => CanSave(tb.Text));

            dialog.IsPrimaryButtonEnabled = false;
            dialog.PrimaryButtonCommand = cmd;
            dialog.SecondaryButtonText = "Cancel";
            dialog.RequestedTheme = (ElementTheme)new Converters.BooleanToThemeConverter().Convert(Settings.UseDarkTheme, null, null, null);
            tb.TextChanged += delegate
            {
                cmd.RaiseCanExecuteChanged();
                if (tb.Text.Trim().Length > 0)
                {
                    dialog.IsPrimaryButtonEnabled = true;
                }
                else
                {
                    dialog.IsPrimaryButtonEnabled = false;
                }

            };

            var result = await dialog.ShowAsync();
            if (result == ContentDialogResult.Primary)
            {
                return play;
            }
            return null;
        }
开发者ID:MichaelAi,项目名称:Aural-Player,代码行数:49,代码来源:ContentDialogService.cs

示例8: SendEDIDManager_VM

        public SendEDIDManager_VM()
        {
            CmdRefashSelectedType = new RelayCommand(OnCmdRefreshSelectedType, CanCmdRefreshSelectedType);
            CmdSetSelectedType = new RelayCommand(OnCmdSetSelectedType, CanCmdSetSelectedType);
            SenderDisplayInfoList.CollectionChanged += (s, e) =>
            {
                switch (e.Action)
                {
                    case System.Collections.Specialized.NotifyCollectionChangedAction.Add:
                    case System.Collections.Specialized.NotifyCollectionChangedAction.Remove:
                    case System.Collections.Specialized.NotifyCollectionChangedAction.Reset:
                    case System.Collections.Specialized.NotifyCollectionChangedAction.Replace:
                        CmdRefashSelectedType.RaiseCanExecuteChanged();
                        CmdSetSelectedType.RaiseCanExecuteChanged();
                        break;
                    default:
                        break;
                }
            };


            if (this.IsInDesignMode)
            {
                DataGradViewItem data = new DataGradViewItem();
                data.SenderIndex = 0;
                data.SerialPort = "COM1";
                data.RefreshRate = 60;
                data.Reslution = "1024*768";
                data.IsChecked = false;
                SenderDisplayInfoList.Add(data);
                data = new DataGradViewItem();
                data.SenderIndex = 1;
                data.SerialPort = "COM1";
                data.RefreshRate = 60;
                data.Reslution = "1024*768";
                data.IsChecked = false;
                SenderDisplayInfoList.Add(data);

                data = new DataGradViewItem();
                data.SenderIndex = 2;
                data.SerialPort = "COM2";
                data.RefreshRate = 60;
                data.Reslution = "1024*768";
                data.IsChecked = false;
                SenderDisplayInfoList.Add(data);
                data = new DataGradViewItem();
                data.SenderIndex = 3;
                data.SerialPort = "COM2";
                data.RefreshRate = 60;
                data.Reslution = "1024*768";
                data.IsChecked = false;
                SenderDisplayInfoList.Add(data);

            }
            else
            {
                Initialize();
            }
        }
开发者ID:SmartEncounter,项目名称:SmartLCT-V2.0,代码行数:59,代码来源:SendEDIDManager_VM.cs

示例9: InitializeView

        private void InitializeView()
        {
            SearchForPositionCommand = new RelayCommand(() =>
            {
                PositionsFoundHashes.Clear();

                var found = _positionService.Find(SearchField);

                if (PositionsFound.Count > 0)
                {
                    var index = 0;
                    do
                    {
                        if (PositionsFound[index] == SelectedPosition)
                            index++;
                        else
                            PositionsFound.RemoveAt(index);
                    } while (index < PositionsFound.Count);
                }

                foreach(var position in found)
                {
                    if (SelectedPosition == null || position.Id != SelectedPosition.Id)
                        PositionsFound.Add(position);
                }

                var hashes = PositionsFound.Select(x => (long)(x.Title + x.Description).GetHashCode());
                PositionsFoundHashes.AddRange(hashes);
            }, () => { return true; });

            SavePositionCommand = new RelayCommand(
                () => {
                    _positionService.Save(SelectedPosition);

                    PositionsFoundHashes.Clear();
                    var hashes = PositionsFound.Select(x => (long)(x.Title + x.Description).GetHashCode());
                    PositionsFoundHashes.AddRange(hashes);

                    SearchField = SelectedPosition.Title;

                    SavePositionCommand.RaiseCanExecuteChanged();
                }
                ,() =>
                {
                    var selectedPositionHash = SelectedPosition == null
                        ? new Random().Next()
                        : (SelectedPosition.Title + SelectedPosition.Description).GetHashCode();

                    return SelectedPosition != null
                        && SelectedPosition.Title != null && SelectedPosition.Title.Length > 1
                        && SelectedPosition.Description != null && SelectedPosition.Description.Length > 1
                        && !PositionsFoundHashes.Contains(selectedPositionHash);
                }
            );

            ClearPositionCommand = new RelayCommand(() =>
            {
                PositionsFound.Clear();
                SelectedPosition = new Position();
                SearchField = "";

            });

            UpdateCanSaveCommand = new RelayCommand(() =>
            {
                SavePositionCommand.RaiseCanExecuteChanged();
            });

            ExpandComboBoxCommand = new RelayCommand(() =>
            {
                ShowMatchingPositions = true;
            });

            SelectedPosition = new Position();
            PositionsFound = new ObservableCollection<Position>();
        }
开发者ID:NeverOddOrEven,项目名称:Parakeet,代码行数:76,代码来源:PositionCenterViewModel.cs

示例10: TreemapViewModel

        public TreemapViewModel(TreemapChart treemap, ChartData data, TreemapAlgorithm algo) : this()
        {
            Treemap = treemap;
            Data = data;
            Columns = Data.ColumnNames;

            Algorithm = algo;
            InitParameters();
            InitColorViewModels();
            SetColorViewModel();

            Messenger.Default.Register<PropertyChangedMessageBase>
            (
                 this, true,
                 (m) =>
                 {
                     if (IsDead || !IsSentBySelf(m.Sender))
                         return;

                     if (m.PropertyName == "ColorMethod")
                         SetColorViewModel();

                     ShowLegendDecimalPlaces = LegendFormatType != FormatType.Text;

                     if (!LockRefresh)
                         DrawChart();
                 }
            );

            RefreshCommand = new RelayCommand<object>(_ => DrawChart(true));

            DeleteCommand = new RelayCommand<object>(
                _ =>
                {
                    LockRefresh = true;
                    Indexes.RemoveAt(Indexes.Count - 1);
                    Indexes.Last().AsChildIndex();

                    DeleteCommand.RaiseCanExecuteChanged();
                    AddCommand.RaiseCanExecuteChanged();

                    DrawChart();
                    LockRefresh = false;
                },
                _ => Indexes.Count > 1);

            AddCommand = new RelayCommand<object>(
                _ =>
                {
                    LockRefresh = true;
                    Indexes.Last().AsParentIndex();

                    string freeColumn = Columns.Where(c => !Indexes.Select(i => i.Column).Contains(c)).First();
                    Indexes.Add(new TreemapIndexViewModel(freeColumn));

                    DeleteCommand.RaiseCanExecuteChanged();
                    AddCommand.RaiseCanExecuteChanged();

                    DrawChart();
                    LockRefresh = false;
                },
                _ => Indexes.Count < Columns.Count);

            DrawChart();
        }
开发者ID:fabien-vavrand,项目名称:excel-charting-toolbox,代码行数:65,代码来源:TreemapViewModel.cs

示例11: FormulaEditorViewModel

        public FormulaEditorViewModel()
        {
            KeyPressedCommand = new RelayCommand<FormulaKeyEventArgs>(KeyPressedAction);
            ShowErrorPressedCommand = new RelayCommand(ShowErrorPressedAction, ShowErrorPressedCommand_CanExecute);
            UndoCommand = new RelayCommand(UndoAction, UndoCommand_CanExecute);
            RedoCommand = new RelayCommand(RedoAction, RedoCommand_CanExecute);
            SensorCommand = new RelayCommand(SensorAction);
            CompleteTokenCommand = new RelayCommand<int>(CompleteTokenAction);
            SaveCommand = new RelayCommand(SaveAction);
            CancelCommand = new RelayCommand(CancelAction);
            
            Messenger.Default.Register<GenericMessage<Sprite>>(this, ViewModelMessagingToken.CurrentSpriteChangedListener, SelectedSpriteChangedMessageAction);
            Messenger.Default.Register<GenericMessage<Program>>(this, ViewModelMessagingToken.CurrentProgramChangedListener, CurrentProgramChangedMessageAction);

            _editor.PropertyChanged += (sender, e) =>
            {
                if (e.PropertyName == GetPropertyName(() => _editor.Formula)) RaisePropertyChanged(() => Formula);
                if (e.PropertyName == GetPropertyName(() => _editor.Tokens)) RaisePropertyChanged(() => Tokens);
                if (e.PropertyName == GetPropertyName(() => _editor.IsTokensEmpty)) RaisePropertyChanged(() => IsTokensEmpty);
                if (e.PropertyName == GetPropertyName(() => _editor.CaretIndex)) RaisePropertyChanged(() => CaretIndex);
                if (e.PropertyName == GetPropertyName(() => _editor.SelectionStart)) RaisePropertyChanged(() => SelectionStart);
                if (e.PropertyName == GetPropertyName(() => _editor.SelectionLength)) RaisePropertyChanged(() => SelectionLength);
                if (e.PropertyName == GetPropertyName(() => _editor.CanUndo))
                {
                    RaisePropertyChanged(() => CanUndo);
                    UndoCommand.RaiseCanExecuteChanged();
                }
                if (e.PropertyName == GetPropertyName(() => _editor.CanRedo))
                {
                    RaisePropertyChanged(() => CanRedo);
                    RedoCommand.RaiseCanExecuteChanged();
                }
                if (e.PropertyName == GetPropertyName(() => _editor.CanDelete)) RaisePropertyChanged(() => CanDelete);
                if (e.PropertyName == GetPropertyName(() => _editor.HasError))
                {
                    RaisePropertyChanged(() => HasError);
                    ShowErrorPressedCommand.RaiseCanExecuteChanged();
                }
                if (e.PropertyName == GetPropertyName(() => _editor.HasError)) RaisePropertyChanged(() => CanEvaluate);
                if (e.PropertyName == GetPropertyName(() => _editor.ParsingError)) RaisePropertyChanged(() => ParsingError);
            };

            _keyboardViewModel = ServiceLocator.ViewModelLocator.FormulaKeyboardViewModel;
            //_keyboardViewModel.PropertyChanged += (sender, e) =>
            //{
            //    if (e.PropertyName == GetPropertyName(() => _keyboardViewModel.IsAddLocalVariableButtonVisible)) RaisePropertyChanged(() => IsAddLocalVariableButtonVisible);
            //    if (e.PropertyName == GetPropertyName(() => _keyboardViewModel.IsAddGlobalVariableButtonVisible)) RaisePropertyChanged(() => IsAddGlobalVariableButtonVisible);
            //};
            _sensorsAreActive = false;
        }
开发者ID:Catrobat,项目名称:CatrobatForWindows,代码行数:50,代码来源:FormulaEditorViewModel.cs


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