本文整理汇总了C#中ICommand.Execute方法的典型用法代码示例。如果您正苦于以下问题:C# ICommand.Execute方法的具体用法?C# ICommand.Execute怎么用?C# ICommand.Execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICommand
的用法示例。
在下文中一共展示了ICommand.Execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InsertMenuItem
public static IApplicationBarMenuItem InsertMenuItem(this IApplicationBar bar, int index, string text, ICommand cmd)
{
var menu = new ApplicationBarMenuItem { Text = text };
menu.Click += (s, e) => cmd.Execute(null);
bar.MenuItems.Insert(index, menu);
return menu;
}
示例2: DoCommand
public static void DoCommand(ICommand command)
{
if (command.Execute()) {
undoStack.Push(command);
redoStack.Clear();
}
}
示例3: Execute
public void Execute(ICommand command, string user)
{
// check user permission to execute command
ICommandContext context = new CommandContext(_repository, user);
command.Execute(context);
}
示例4: TryExecute
public static void TryExecute(ICommand command)
{
if (command != null)
{
command.Execute(null);
}
}
示例5: PushButton
public void PushButton()
{
if (_reader.CommandData != null)
{
if (_commands.ContainsKey(_reader.CommandData))
{
_command = _commands[_reader.CommandData];
try
{
_command.Execute(_reader);
}
catch (Exception exception)
{
_reader.Help(this, exception.Message);
}
}
else
{
_reader.Help(this, "Неправильно введена команда!");
}
}
else
{
_reader.Help(this, null);
}
}
示例6: TrayWindowViewModel
public TrayWindowViewModel(TaskbarIcon taskbarIcon)
{
_taskbarIcon = taskbarIcon;
ExitCommand = new ExitCommand();
ShowCommand = new ShowAllCommand();
HideCommand = new HideAllCommand();
AddRepoCommand = new AddRepositoryCommand();
ShowAboutCommand = new ShowSingleViewCommand(typeof(AboutView));
LeftClickCommand = new ToggleShowHideCommand();
DoubleClickCommand = LeftClickCommand;
ShowSettingsCommand = new ShowSingleViewCommand(typeof(SettingsView));
#if DEBUG
ShowSettingsVisiblilty = "Visible";
#else
ShowSettingsVisiblilty = "Collapsed";
#endif
ShowUpdateCommand = new ShowSingleViewCommand(typeof(UpdateView));
CheckUpdateCommand = ShowUpdateCommand;
HotkeyHelper.OnHotkeyChanged += (sender, args) => OnPropertyChanged("ShowHideHeader");
// todo: currently the only balloon is for update, so no distinction about what to do.
_taskbarIcon.TrayBalloonTipClicked += (sender, args) => ShowUpdateCommand.Execute(null);
UpdateManager.OnUpdateRequired += UpdateManager_OnUpdateRequired;
UpdateManager.OnUpdateInfoChanged += delegate(object sender, EventArgs args)
{
OnPropertyChanged("CheckUpdateHeader");
OnPropertyChanged("ToolTipText");
};
}
示例7: Handle
public Notification Handle(ICommand command, ExecutionArguments executionArguments)
{
var prerequisiteResult = _prerequisiteChecker.Check(command, executionArguments);
if (prerequisiteResult.HasErrors)
{
return prerequisiteResult;
}
var commandResult = command.Execute(executionArguments);
if (commandResult.HasErrors)
{
return commandResult;
}
if (command.ChangesTheStatement())
{
var commandHistory = new CommandHistory
{
Command = command.GetType().Name,
Args = executionArguments.Args,
Date = _systemService.CurrentDateTime
};
Statement statement = executionArguments.Statement;
statement.CommandHistory.Add(commandHistory);
}
return commandResult;
}
示例8: InsertGeFile
public void InsertGeFile(string filename, GraphicContent graphicContent)
{
f_command = new InsertGeFileCommand(filename, graphicContent);
f_undoCommands.Push(f_command);
f_redoCommands.Clear();
f_command.Execute();
}
示例9: Include
public void Include (ICommand command)
{
command.CanExecuteChanged += (s, e) => {
if (command.CanExecute (null))
command.Execute (null);
};
}
示例10: Execute
/// <summary>
/// The main execution method to decouple actions. Track
/// commands in this method if you need to Undo or Redo actions.
/// </summary>
public void Execute(ICommand command)
{
command.Execute();
UndoneCommands.Clear();
RedoneCommands.Clear();
Commands.Push(command);
}
示例11: Execute
public void Execute(ICommand command)
{
command.Execute();
undoStack.Push(command);
redoStack.Clear();
}
示例12: InsertButton
public static IApplicationBarIconButton InsertButton(this IApplicationBar bar, int index, string imageUrl, string text, ICommand cmd)
{
var btn = new ApplicationBarIconButton { IconUri = new Uri(imageUrl, UriKind.Relative), Text = text };
btn.Click += (s, e) => cmd.Execute(null);
bar.Buttons.Insert(index, btn);
return btn;
}
示例13: CreateAndAddMenuItem
/// <summary>
/// Creates a menu item and adds it to an application bar.
/// </summary>
/// <param name="appBar"></param>
/// <param name="command"></param>
/// <param name="text"></param>
/// <returns></returns>
public static ApplicationBarMenuItem CreateAndAddMenuItem(this IApplicationBar appBar, ICommand command, string text)
{
ApplicationBarMenuItem mi = new ApplicationBarMenuItem(text);
// First-time values.
mi.IsEnabled = command.CanExecute(mi);
// Adds click handler to execute the command upon click.
mi.Click += (o, e) =>
{
if (command.CanExecute(mi))
{
command.Execute(mi);
}
};
// Adds CanExecute changed handler.
command.CanExecuteChanged += (o, e) =>
{
mi.IsEnabled = command.CanExecute(mi);
};
// Adds the button.
appBar.MenuItems.Add(mi);
return mi;
}
示例14: DoesNewPageCommandExecute
protected bool DoesNewPageCommandExecute(ICommand command, PageName expected)
{
var passedNewPage = PageName.Navigation;
Commands.NewPageCommand = new RelayCommand<PageName>(p => passedNewPage = p);
command.Execute(null);
return passedNewPage.Equals(expected);
}
示例15: CreateAndAddButton
/// <summary>
/// Creates a button and adds it to an application bar.
/// </summary>
/// <param name="appBar"></param>
/// <param name="iconFilenameRelative"></param>
/// <param name="command"></param>
/// <param name="text"></param>
/// <returns></returns>
public static ApplicationBarIconButton CreateAndAddButton(this IApplicationBar appBar, string iconFilenameRelative, ICommand command, string text)
{
ApplicationBarIconButton btn = new ApplicationBarIconButton(new Uri("/icons/" + iconFilenameRelative, UriKind.Relative));
// First-time values.
btn.IsEnabled = command.CanExecute(btn);
btn.Text = text;
// Adds click handler to execute the command upon click.
btn.Click += (o, e) =>
{
if (command.CanExecute(btn))
{
command.Execute(btn);
}
};
// Adds CanExecute changed handler.
command.CanExecuteChanged += (o, e) =>
{
btn.IsEnabled = command.CanExecute(btn);
};
// Adds the button.
appBar.Buttons.Add(btn);
return btn;
}