本文整理汇总了C#中System.Windows.Input.DelegateCommand.RaiseCanExecuteChanged方法的典型用法代码示例。如果您正苦于以下问题:C# DelegateCommand.RaiseCanExecuteChanged方法的具体用法?C# DelegateCommand.RaiseCanExecuteChanged怎么用?C# DelegateCommand.RaiseCanExecuteChanged使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Input.DelegateCommand
的用法示例。
在下文中一共展示了DelegateCommand.RaiseCanExecuteChanged方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Raise2TimesExecuteChanged
public void Raise2TimesExecuteChanged()
{
DelegateCommand command = new DelegateCommand(() => { });
AssertHelper.CanExecuteChangedEvent(command, () =>
{
command.RaiseCanExecuteChanged();
command.RaiseCanExecuteChanged();
});
}
示例2: VisualizationStateViewModel
public VisualizationStateViewModel( string name, ObservableCollection<object> allRecords )
{
_name = name;
_allRecords = allRecords;
_recordsPaneVisiblity = Visibility.Collapsed;
_showOrHideRecordsCommand = new DelegateCommand<object>(OnShowOrHideRecords, CanShowOrHideRecords);
_exportImageCommand = new DelegateCommand<object>(OnExportImage, CanExportImage);
_allRecords.CollectionChanged +=
(s, a) =>
{
Action action = () =>
{
NotifyOfPropertyChange(() => HasRecords);
_showOrHideRecordsCommand.RaiseCanExecuteChanged();
};
if( null != Dispatcher && ! Dispatcher.CheckAccess() )
{
Dispatcher.BeginInvoke(action, DispatcherPriority.Normal, null);
}
else
{
action();
}
};
}
示例3: InboxViewModel
public InboxViewModel(IEmailService emailService, IRegionManager regionManager)
{
synchronizationContext = SynchronizationContext.Current ?? new SynchronizationContext();
_composeMessageCommand = new DelegateCommand<object>(ComposeMessage);
_replyMessageCommand = new DelegateCommand<object>(ReplyMessage, CanReplyMessage);
_openMessageCommand = new DelegateCommand<EmailDocument>(OpenMessage);
messagesCollection = new ObservableCollection<EmailDocument>();
Messages = new CollectionView(this.messagesCollection);
Messages.CurrentChanged += (s, e) =>
_replyMessageCommand.RaiseCanExecuteChanged();
_emailService = emailService;
_regionManager = regionManager;
if (_emailService != null)
{
_emailService.BeginGetEmailDocuments(
r =>
{
var messages = _emailService.EndGetEmailDocuments(r);
synchronizationContext.Post(
s =>
{
foreach (var message in messages)
{
messagesCollection.Add(message);
}
}, null);
}, null);
}
}
示例4: RaiseCanExecuteChangedRaisesCanExecuteChanged
public void RaiseCanExecuteChangedRaisesCanExecuteChanged()
{
var handlers = new DelegateHandlers();
var command = new DelegateCommand<object>(handlers.Execute);
bool canExecuteChangedRaised = false;
command.CanExecuteChanged += delegate { canExecuteChangedRaised = true; };
command.RaiseCanExecuteChanged();
Assert.IsTrue(canExecuteChangedRaised);
}
示例5: Init
public void Init(Model model) {
InitializeComponent();
try {
OnCompleted += () => {
disposables.Dispose();
};
disposables.Add(Observable.FromEventPattern<MouseWheelEventArgs>(scroll, "PreviewMouseWheel")
.Subscribe(evarg => {
scroll.ScrollToVerticalOffset(-1 * evarg.EventArgs.Delta);
})
);
listReceivers.ItemsSource = model.receivers;
listReceivers.CreateBinding(ListBox.SelectedValueProperty, model, x => x.selection, (m, o) => {
m.selection = o;
});
var createReceiverCommand = new DelegateCommand(
() => Success(new Result.Create(model)),
() => true
);
createReceiverButton.Command = createReceiverCommand;
var deleteReceiverCommand = new DelegateCommand(
() => Success(new Result.Delete(model)),
() => model.selection != null
);
deleteReceiverButton.Command = deleteReceiverCommand;
var modifyReceiverCommand = new DelegateCommand(
() => Success(new Result.Modify(model)),
() => model.selection != null
);
modifyReceiverButton.Command = modifyReceiverCommand;
disposables.Add(
model
.GetPropertyChangedEvents(m => m.selection)
.Subscribe(v => {
modifyReceiverCommand.RaiseCanExecuteChanged();
deleteReceiverCommand.RaiseCanExecuteChanged();
})
);
} catch(Exception err) {
dbg.Error(err);
}
}
示例6: CanExecuteChanged
public void CanExecuteChanged()
{
bool b = false;
int i = 0;
Action execute = (() => { });
Func<bool> predicate = (() => b);
var command = new DelegateCommand(execute, predicate);
EventHandler eventHandler = (sender, eventArgs) =>
{
Assert.AreSame(command, sender);
Assert.IsNotNull(eventArgs);
i++;
};
command.CanExecuteChanged += eventHandler;
command.RaiseCanExecuteChanged();
Assert.AreEqual(1, i);
command.RaiseCanExecuteChanged();
command.RaiseCanExecuteChanged();
Assert.AreEqual(3, i);
command.CanExecuteChanged -= eventHandler;
command.RaiseCanExecuteChanged();
Assert.AreEqual(3, i);
}
示例7: MainWindowViewModel
public MainWindowViewModel()
{
_BrowseFolderCommand = new DelegateCommand(DoBrowseFolderCommand, CanDoBrowseFolderCommand);
_CloseFolderCommand = new DelegateCommand(DoCloseFolderCommand, CanDoCloseFolderCommand);
_GotoFirstFileCommand = new DelegateCommand(DoGotoFirstFileCommand, CanDoGotoFirstFileCommand);
_GotoPreviousFileCommand = new DelegateCommand(DoGotoPreviousFileCommand, CanDoGotoPreviousFileCommand);
_GotoNextFileCommand = new DelegateCommand(DoGotoNextFileCommand, CanDoGotoNextFileCommand);
_GotoLastFileCommand = new DelegateCommand(DoGotoLastFileCommand, CanDoGotoLastFileCommand);
_GotoImageNameCommand = new DelegateCommand(DoGotoImageNameCommand, CanDoGotoImageNameCommand);
_ZoomInCommand = new DelegateCommand(DoZoomInCommand, CanDoZoomInCommandCommand);
_ZoomOutCommand = new DelegateCommand(DoZoomOutCommand, CanDoZoomOutCommandCommand);
_ActualSizeCommand = new DelegateCommand(DoActualSizeCommand, CanDoActualSizeCommandCommand);
_ZoomFitCommand = new DelegateCommand(DoZoomFitCommand, CanDoZoomFitCommandCommand);
_FitWidthCommand = new DelegateCommand(DoFitWidthCommand, CanDoFitWidthCommandCommand);
_FitHeightCommand = new DelegateCommand(DoFitHeightCommand, CanDoFitHeightCommandCommand);
_RenameActiveImageCommand = new DelegateCommand(DoRenameActiveImageCommand, CanDoRenameActiveImageCommand);
_DeleteActiveImageCommand = new DelegateCommand(DoDeleteActiveImageCommand, CanDoDeleteActiveImageCommand);
_RefreshActiveImageCommand = new DelegateCommand(DoRefreshActiveImageCommand, CanDoRefreshActiveImageCommandCommand);
_AboutCommand = new DelegateCommand(DoAboutCommand, CanDoAboutCommand);
_ActiveImagesViewModel = new ActiveImagesViewModel();
_ActiveImagesViewModel.ActiveFilesCollection.CollectionChanged += (s, e) =>
{
_CloseFolderCommand.RaiseCanExecuteChanged();
RaisePositionCommandEvents();
RaiseZoomCommandEvents();
RaiseFileOperationEvents();
};
_ActiveImagesViewModel.ActiveImageChanged += (s, e) =>
{
RaisePositionCommandEvents();
};
_ActiveImagesViewModel.PropertyChanged += (s, e) =>
{
switch (e.PropertyName)
{
case "IsLoadingFiles":
RaiseFileOperationEvents();
break;
}
};
}
示例8: GoogleProvider
//TODO: Inject a Func<IGoogleLoginView> instead
public GoogleProvider(IAuthorizationModel authorizationModel, IRegionManager regionManager, IGoogleLoginView loginView, ILoggerFactory loggerFactory)
{
_authorizationModel = authorizationModel;
_regionManager = regionManager;
_loginView = loginView;
_logger = loggerFactory.GetLogger();
_logger.Debug("GoogleProvider.ctor(...)");
_regionManager.Regions["WindowRegion"].Add(_loginView);
_authorizationModel.RegisterAuthorizationCallback(ShowGoogleLogin);
_authorizeCommand = new DelegateCommand(RequestAuthorization, () => !Status.IsAuthorized && !Status.IsProcessing);
_authorizationModel.Status.Subscribe(_ =>
{
OnPropertyChanged("Status");
_authorizeCommand.RaiseCanExecuteChanged();
});
}
示例9: ResizeCommandsViewModel
public ResizeCommandsViewModel(IResizeViewModel resizeViewModel, IResizeService resizeService)
{
if(resizeViewModel == null)
throw new ArgumentNullException("resizeViewModel");
if(resizeService == null)
throw new ArgumentNullException("resizeService");
this.resizeViewModel = resizeViewModel;
this.resizeService = resizeService;
resizeFileCommand = new DelegateCommand(Resize, CanResize);
resizeFolderCommand = new DelegateCommand(ResizeFolder, CanResize);
Observable.FromEventPattern<PropertyChangedEventArgs>(this.resizeViewModel, "PropertyChanged")
.Subscribe(x =>
{
resizeFileCommand.RaiseCanExecuteChanged();
resizeFolderCommand.RaiseCanExecuteChanged();
});
}
示例10: CanRemoveCanExecuteChangedHandler
public void CanRemoveCanExecuteChangedHandler()
{
var command = new DelegateCommand<object>((o) => { });
bool canExecuteChangedRaised = false;
EventHandler handler = (s, e) => canExecuteChangedRaised = true;
command.CanExecuteChanged += handler;
command.CanExecuteChanged -= handler;
command.RaiseCanExecuteChanged();
Assert.IsFalse(canExecuteChangedRaised);
}
示例11: OnLoggedIn
void OnLoggedIn(dynamic result)
{
if (result["Result"].ToObject<bool>())
{
m_FieldMetadatas = result["FieldMetadatas"].ToObject<StateFieldMetadata[]>();
var nodeInfo = DynamicViewModelFactory.Create(result["NodeInfo"].ToString());
BuildGridColumns(m_FieldMetadatas);
GlobalInfo = nodeInfo.GlobalInfo;
var instances = nodeInfo.Instances 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);
i.PropertyChanged += (s, e) =>
{
if (string.IsNullOrEmpty(e.PropertyName)
|| e.PropertyName.Equals("IsRunning", StringComparison.OrdinalIgnoreCase))
{
startCommand.RaiseCanExecuteChanged();
stopCommand.RaiseCanExecuteChanged();
}
};
i.Set("StartCommand", startCommand);
i.Set("StopCommand", stopCommand);
return i;
}));
State = NodeState.Connected;
LastUpdatedTime = DateTime.Now;
}
else
{
m_LoginFailed = true;
//login failed
m_WebSocket.Close();
ErrorMessage = "Logged in failed!";
}
}
示例12: Precondition_Command_Null
public void Precondition_Command_Null()
{
DelegateCommand command = new DelegateCommand(() => { });
AssertHelper.CanExecuteChangedEvent(null, () => command.RaiseCanExecuteChanged());
}
示例13: CommandCanExecuteChangedTest
public void CommandCanExecuteChangedTest()
{
DelegateCommand command = new DelegateCommand(() => { });
AssertHelper.CanExecuteChangedEvent(command, () => command.RaiseCanExecuteChanged());
}
示例14: Init
public void Init(Model model) {
InitializeComponent();
OnCompleted += () => {
disposables.Dispose();
};
var availableActions = new ObservableCollection<Action1>();
var includedActions = new ObservableCollection<Action1>();
var applyCommand = new DelegateCommand(
() => {
model.trigger.Configuration.TopicExpression = GetTopicExression();
if (string.IsNullOrEmpty(model.trigger.Configuration.TopicExpression.Any.First().InnerText))
model.trigger.Configuration.TopicExpression = null;
if (string.IsNullOrEmpty(model.trigger.Configuration.ContentExpression.Any.First().InnerText))
model.trigger.Configuration.ContentExpression = null;
model.trigger.Configuration.ActionToken = includedActions.Select(a => a.Token).ToArray();
Success(new Result.Apply(model));
},
() => true
);
applyButton.Command = applyCommand;
var cancelCommand = new DelegateCommand(
() => Success(new Result.Cancel(model)),
() => true
);
cancelButton.Command = cancelCommand;
FixModel(model);
{ // token
valueToken.CreateBinding(TextBlock.TextProperty, model.trigger, x => x.Token);
if (string.IsNullOrEmpty(model.trigger.Token)) {
captionToken.Visibility = Visibility.Collapsed;
valueToken.Visibility = Visibility.Collapsed;
}
}
{ // topic filter
var concreteSetTopics = GetConcreteSetTopics(model.topicSet);
concreteSetTopics.Insert(0, string.Empty);
var topicExpr = model.trigger.Configuration.TopicExpression.Any.First().InnerText;
var topicExprParts = topicExpr.Split(new char[] { '|' });
foreach (var part in topicExprParts) {
var control = CreateTopicExprControl(concreteSetTopics, part);
valuesTopicExpr.Items.Add(control);
}
var addTopicExprPartCommand = new DelegateCommand(
executeMethod: () => {
var control = CreateTopicExprControl(concreteSetTopics, string.Empty);
valuesTopicExpr.Items.Add(control);
},
canExecuteMethod: () => valuesTopicExpr.Items.Count <= 32
);
addTopicExprPartButton.Command = addTopicExprPartCommand;
}
{ // content filter
valueContentExpr.CreateBinding(TextBox.TextProperty, model.trigger.Configuration.ContentExpression
, m => m.Any.First().InnerText
, (m, v) => m.Any = new XmlNode[] { new XmlDocument().CreateTextNode(v) });
}
{ // actions
var addActionCommand = new DelegateCommand(
() => {
var actions = (listAvailableActions.SelectedItems ?? new ArrayList()).Select(i => (Action1)i).ToList();
availableActions.RemoveRange(actions);
includedActions.AddRange(actions);
},
() => (listAvailableActions.SelectedItems ?? new ArrayList()).Count > 0
);
addActionButton.Command = addActionCommand;
var removeActionCommand = new DelegateCommand(
() => {
var actions = (listIncludedActions.SelectedItems ?? new ArrayList()).Select(i => (Action1)i).ToList();
includedActions.RemoveRange(actions);
availableActions.AddRange(actions);
},
() => (listIncludedActions.SelectedItems ?? new ArrayList()).Count > 0
);
removeActionButton.Command = removeActionCommand;
includedActions.AddRange(model.trigger.Configuration.ActionToken.Select(token => model.actions.First(a => a.Token == token)).ToList());
availableActions.AddRange(model.actions.Except(includedActions).ToList());
listAvailableActions.ItemsSource = availableActions;
listIncludedActions.ItemsSource = includedActions;
listIncludedActions.SelectionChanged += delegate { removeActionCommand.RaiseCanExecuteChanged(); };
listAvailableActions.SelectionChanged += delegate { addActionCommand.RaiseCanExecuteChanged(); };
}
Localization();
}
示例15: ShouldReraiseDelegateCommandCanExecuteChangedEventAfterCollect
public void ShouldReraiseDelegateCommandCanExecuteChangedEventAfterCollect()
{
TestableCompositeCommand multiCommand = new TestableCompositeCommand();
DelegateCommand<object> delegateCommand = new DelegateCommand<object>(delegate { });
Assert.False(multiCommand.CanExecuteChangedRaised);
multiCommand.RegisterCommand(delegateCommand);
multiCommand.CanExecuteChangedRaised = false;
GC.Collect();
delegateCommand.RaiseCanExecuteChanged();
Assert.True(multiCommand.CanExecuteChangedRaised);
}