本文整理汇总了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);
}
示例2: MultiViewModel
public MultiViewModel()
{
SelectAllCommand = new DelegateCommand(SelectAll);
ClearSelectionCommand = new DelegateCommand(ClearSelection, CanClearSelection);
SelectedItems = new ObservableCollection<ItemViewModel>();
SelectedItems.CollectionChanged += (sender, args) => ClearSelectionCommand.RaiseCanExecuteChanged();
}
示例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();
}));
}
示例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();
}
示例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));
}
示例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);
}
示例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"));
}
示例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));
}
示例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!";
}
}