/// Static private constructor, sets up all application wide commands. static CommandBank(){ CloseWindowCommand = new RoutedUICommand(); /* * --------------------- Input Binding --------------------------------- */ CloseWindowCommand.InputGestures.Add(new KeyGesture(Key.F4, ModifierKeys.Alt)); // ... }
static GameCommands() { // Initialize the command. //InputGestureCollection inputs = new InputGestureCollection(); //inputs.Add(new KeyGesture(Key.R, ModifierKeys.Control, "Ctrl+R")); _start = new RoutedUICommand("Start", "Start", typeof(GameCommands)); // Initialize the command. //InputGestureCollection inputs = new InputGestureCollection(); //inputs.Add(new KeyGesture(Key.R, ModifierKeys.Control, "Ctrl+R")); _showThemes = new RoutedUICommand("ShowTheme", "ShowTheme", typeof(GameCommands)); _showSettings = new RoutedUICommand("ShowSettings", "ShowSettings", typeof(GameCommands)); _showStatistic = new RoutedUICommand("ShowStatistic", "ShowStatistic", typeof(GameCommands)); _exit = new RoutedUICommand("Exit", "Exit", typeof(GameCommands)); _newLexim = new RoutedUICommand("NewLexim", "NewLexim", typeof(GameCommands)); _saveLexim = new RoutedUICommand("SaveLexim", "SaveLexim", typeof(GameCommands)); _deleteLexim = new RoutedUICommand("SaveLexim", "SaveLexim", typeof(GameCommands)); _newTheme = new RoutedUICommand("NewTheme", "NewTheme", typeof(GameCommands)); _saveTheme = new RoutedUICommand("SaveTheme", "SaveTheme", typeof(GameCommands)); _deleteTheme = new RoutedUICommand("SaveTheme", "SaveTheme", typeof(GameCommands)); }
//Design Pattern: Command design pattern static treeViewCommands() { InputGestureCollection inputsExpand = new InputGestureCollection(); inputsExpand.Add(new KeyGesture(Key.E, ModifierKeys.Control, "Ctrl+E")); _expand = new RoutedUICommand( "Expand", "Expand", typeof(treeViewCommands), inputsExpand); InputGestureCollection inputsCollapse = new InputGestureCollection(); inputsCollapse.Add(new KeyGesture(Key.X, ModifierKeys.Control, "Ctrl+X")); _collapse = new RoutedUICommand( "Collapse", "Collapse", typeof(treeViewCommands), inputsCollapse); InputGestureCollection inputsCopyName = new InputGestureCollection(); inputsCopyName.Add(new KeyGesture(Key.C, ModifierKeys.Control, "Ctrl+C")); _copyName = new RoutedUICommand( "CopyName", "CopyName", typeof(treeViewCommands), inputsCopyName); }
static ExecutedRoutedEventHandler OnDelete(RoutedUICommand selectingCommand) { return((target, args) => { TextArea textArea = GetTextArea(target); if (textArea != null && textArea.Document != null) { // call BeginUpdate before running the 'selectingCommand' // so that undoing the delete does not select the deleted character using (textArea.Document.RunUpdate()) { if (textArea.Selection.IsEmpty) { selectingCommand.Execute(args.Parameter, textArea); } textArea.RemoveSelectedText(); } textArea.Caret.BringCaretToView(); args.Handled = true; } }); }
static ApplicationCommand() { // initialize the command InputGestureCollection inputs = new InputGestureCollection(); inputs.Add(new KeyGesture(Key.M, ModifierKeys.Control, "Ctrl+M")); make = new RoutedUICommand("Make", "Make", typeof(ApplicationCommand), inputs); exit = new RoutedUICommand("Exit", "Exit", typeof(ApplicationCommand)); preference = new RoutedUICommand("Preference", "Preference", typeof(ApplicationCommand)); about = new RoutedUICommand("About", "About", typeof(ApplicationCommand)); discuss = new RoutedUICommand("Discuss", "Discuss", typeof(ApplicationCommand)); addWatermark = new RoutedUICommand("AddWatermark", "AddWatermark", typeof(ApplicationCommand)); deleteWatermark = new RoutedUICommand("DeleteWatermark", "DeleteWatermark", typeof(ApplicationCommand)); }
/// <summary> /// Define custom commands and their key gestures /// </summary> static AppCommand() { InputGestureCollection inputs = null; // Initialize pin command (to set or unset a pin in MRU and re-sort list accordingly) inputs = new InputGestureCollection(); AppCommand.pinUnpin = new RoutedUICommand("Pin or Unpin", "Pin", typeof(AppCommand), inputs); // Execute add recent files list etnry pin command (to add another MRU entry into the list) inputs = new InputGestureCollection(); AppCommand.addMruEntry = new RoutedUICommand("Add Entry", "AddEntry", typeof(AppCommand), inputs); // Execute remove pin command (remove a pin from a recent files list entry) inputs = new InputGestureCollection(); AppCommand.removeMruEntry = new RoutedUICommand("Remove Entry", "RemoveEntry", typeof(AppCommand), inputs); // Execute file open command (without user interaction) inputs = new InputGestureCollection(); AppCommand.loadFile = new RoutedUICommand("Open ...", "LoadFile", typeof(AppCommand), inputs); }
private static bool GetSystemGestureText(RoutedUICommand command, FrameworkElement source, out string displayString) { if (source is IGestureSource AsGestureSource) { IGestureTranslator?Translator = AsGestureSource.GestureTranslator; if (Translator != null) { foreach (InputGesture Gesture in command.InputGestures) { if (GestureToText(Gesture, Translator, out displayString)) { return(true); } } } } displayString = string.Empty; return(false); }
/// <summary> /// 静态构造函数 /// </summary> static ControlAttachProperty() { //ClearTextCommand ClearTextCommand = new RoutedUICommand(); ClearTextCommandBinding = new CommandBinding(ClearTextCommand); ClearTextCommandBinding.Executed += ClearButtonClick; //OpenFileCommand OpenFileCommand = new RoutedUICommand(); OpenFileCommandBinding = new CommandBinding(OpenFileCommand); OpenFileCommandBinding.Executed += OpenFileButtonClick; //OpenFolderCommand OpenFolderCommand = new RoutedUICommand(); OpenFolderCommandBinding = new CommandBinding(OpenFolderCommand); OpenFolderCommandBinding.Executed += OpenFolderButtonClick; SaveFileCommand = new RoutedUICommand(); SaveFileCommandBinding = new CommandBinding(SaveFileCommand); SaveFileCommandBinding.Executed += SaveFileButtonClick; }
public ModelsViewModel() { Periods = new ObservableCollection <PeriodViewModel>(); SemiTrimesters = new ObservableCollection <SemiTrimesterViewModel>(); Trimesters = new ObservableCollection <int>(); PeriodModels = new ObservableCollection <string>(); SemiTrimesterModels = new ObservableCollection <string>(); TrimesterModels = new ObservableCollection <string>(); OpenPeriodModelsPathCommand = new RoutedUICommand("OpenPeriodModelsPath", "OpenPeriodModelsPath", typeof(ModelsViewModel)); OpenSemiTrimesterModelsPathCommand = new RoutedUICommand("OpenSemiTrimesterModelsPath", "OpenSemiTrimesterModelsPath", typeof(ModelsViewModel)); OpenTrimesterModelsPathCommand = new RoutedUICommand("OpenTrimesterModelsPath", "OpenTrimesterModelsPath", typeof(ModelsViewModel)); Bindings = new CommandBindingCollection() { new CommandBinding(OpenPeriodModelsPathCommand, OpenPeriodModelsPathExecuted, OpenPeriodModelsPathCanExecute), new CommandBinding(OpenSemiTrimesterModelsPathCommand, OpenSemiTrimesterModelsPathExecuted, OpenSemiTrimesterModelsPathCanExecute), new CommandBinding(OpenTrimesterModelsPathCommand, OpenTrimesterModelsPathExecuted, OpenTrimesterModelsPathCanExecute), }; }
public Xaml() { InitializeComponent(); editor.Text = startDocument; try { Clipboard.SetData(DataFormats.Text, linearGradientBrush); } catch (Exception ex) { // TODO - sometimes calling clipboard.setdata fails with a COM exception } InputGestureCollection updateUIGestures = new InputGestureCollection(); updateUIGestures.Add(new KeyGesture(Key.Q, ModifierKeys.Alt)); RoutedUICommand updateUICommand = new RoutedUICommand("Update UI", "Update UI", GetType(), updateUIGestures); CommandBindings.Add(new CommandBinding(updateUICommand, new ExecutedRoutedEventHandler(this.UpdateFromXamlCode))); }
static PaintCanvasCommands() { ClearCanvas = new RoutedUICommand( "Clear Canvas", "ClearCanvas", typeof(PaintCanvasCommands)); UndoCanvas = new RoutedUICommand( "Undo my last stroke", "UndoCanvas", typeof(PaintCanvasCommands)); ChangeToPencil = new RoutedUICommand( "Pencil", "ChangeToPencil", typeof(PaintCanvasCommands)); ChangeToEraser = new RoutedUICommand( "Eraser", "ChangeToEraser", typeof(PaintCanvasCommands)); ChangeToLine = new RoutedUICommand("Line", "ChangeToLine", typeof(PaintCanvasCommands)); }
static Commands() { // FileBrowse Browse = new RoutedUICommand("Browse", "Brwose", typeof(Commands)); // ConvertTo ConvertTo = new RoutedUICommand("Convert", "ConvertTo", typeof(Commands)); // ConvertToBinary ConvertToBinary = new RoutedUICommand("Convert", "ConvertToBinary", typeof(Commands)); // ConvertToXml ConvertToXml = new RoutedUICommand("Convert", "ConvertToXml", typeof(Commands)); // Exit Exit = new RoutedUICommand("Exit", "Exit", typeof(Commands), new InputGestureCollection { new KeyGesture(Key.F4, ModifierKeys.Alt) }); }
static WindowCommands() { InputGestureCollection input = new InputGestureCollection { new KeyGesture(Key.Enter, ModifierKeys.Alt, "Alt+Enter") }; Maximize = new RoutedUICommand("Maximize window", "Maximize", typeof(WindowCommands), input); input = new InputGestureCollection { new KeyGesture(Key.Enter, ModifierKeys.Alt, "Alt+Enter") }; Restore = new RoutedUICommand("Restore window", "Restore", typeof(WindowCommands), input); Minimize = new RoutedUICommand("Minimize window", "Minimize", typeof(WindowCommands)); input = new InputGestureCollection { new KeyGesture(Key.F4, ModifierKeys.Alt, "Alt+F4") }; Close = new RoutedUICommand("Close window", "Close", typeof(WindowCommands), input); }
public XMLOutputControl() { InitializeComponent(); // Binding with the ChangedIndexCommand on GridPaging......................................... // Create de Command. this.changedIndex = new RoutedUICommand("ChangedIndex", "ChangedIndex", typeof(XMLOutputControl)); // Assing the command to GridPaging Command. pagingControl.ChangedIndexCommand = this.changedIndex; // Binding Command CommandBinding abinding = new CommandBinding { Command = this.changedIndex }; // Binding Handler to executed. abinding.Executed += this.OnChangeIndexCommandHandler; this.CommandBindings.Add(abinding); }
public MainWindow() { InitializeComponent(); DataContext = this; Movies = new ObservableCollection <Movie>() { new Movie("Lock, Stock and Two Smoking Barrels", 4), new Movie("Life of Brian", 5), }; var addMovieCommand = new RoutedUICommand(); CommandManager.RegisterClassCommandBinding(typeof(Window), new CommandBinding( addMovieCommand, (sender, args) => AddMovie(), (sender, args) => args.CanExecute = true)); AddMovieCommand = addMovieCommand; }
private static RoutedUICommand EnsureCommand(CommandId commandId) { var id = (int)commandId; if ((id < 0) || (id >= CommandsCount)) { return(null); } lock (InternalCommands.SyncRoot) { if (InternalCommands[id] == null) { var newCommand = new RoutedUICommand( GetUIText(commandId), commandId.ToString(), typeof(RadSchedulerCommands)); InternalCommands[id] = newCommand; } } return(InternalCommands[id]); }
static Commands() { _inputFolderName = new RoutedUICommand("InputFolderName", "InputFolderName", typeof(Commands)); _newFolder = new RoutedUICommand("NewFolder", "NewFolder", typeof(Commands), new InputGestureCollection() { new KeyGesture(Key.F, ModifierKeys.Control, " Ctrl+F") }); _importFile = new RoutedUICommand("ImportFile", "ImportFile", typeof(Commands), new InputGestureCollection() { new KeyGesture(Key.A, ModifierKeys.Control, " Ctrl+A") }); _removeResourceNode = new RoutedUICommand("RemoveResourceNode", "RemoveResourceNode", typeof(Commands), new InputGestureCollection() { new KeyGesture(Key.Delete, ModifierKeys.None, " Del") }); _renameResourceNode = new RoutedUICommand("RenameResourceNode", "RenameResourceNode", typeof(Commands), new InputGestureCollection() { new KeyGesture(Key.F2, ModifierKeys.None, " F2") }); _renameResourceNodeDlg = new RoutedUICommand("RenameResourceNodeDlg", "RenameResourceNodeDlg", typeof(Commands)); }
private void SetMenuProperties(MenuItem menuItem, DocumentGrid dg, RoutedUICommand command, string header, string inputGestureText) { menuItem.Command = command; menuItem.CommandTarget = dg.DocumentViewerOwner; // the text editor expects the commands to come from the DocumentViewer if (header == null) { menuItem.Header = command.Text; // use default menu text for this command } else { menuItem.Header = header; } if (inputGestureText != null) { menuItem.InputGestureText = inputGestureText; } menuItem.Name = "ViewerContextMenu_" + command.Name; // does not require localization this.Items.Add(menuItem); }
private static RoutedUICommand _EnsureCommand(ControlCommands.CommandId idCommand) { if (idCommand >= (ControlCommands.CommandId) 0 && idCommand < ControlCommands.CommandId.Last) { lock (ControlCommands._internalCommands.SyncRoot) { if (ControlCommands._internalCommands[(int)idCommand] == null) { RoutedUICommand routedUICommand = new RoutedUICommand( ControlCommands.GetPropertyName(idCommand), ControlCommands.GetPropertyName(idCommand), typeof(ControlCommands)); ControlCommands._internalCommands[(int)idCommand] = routedUICommand; } } return(ControlCommands._internalCommands[(int)idCommand]); } return(null); }
public void IsExecutingTest() { RoutedUICommand testCommand = new RoutedUICommand ( "test", nameof(testCommand), typeof(MainWindow) ); var result0 = testCommand.IsExecuting(); testCommand.SetIsRunning(true); var result1 = testCommand.IsExecuting(); testCommand.SetIsRunning(false); var result2 = testCommand.IsExecuting(); Assert.IsFalse(result0, "IsExecutingTest FAIL"); Assert.IsTrue(result1, "IsExecutingTest FAIL"); Assert.IsFalse(result2, "IsExecutingTest FAIL"); }
static SelectorCommands() { SelectPrev = new RoutedUICommand("Select previous item", "SelectPrev", typeof(SelectorCommands), new InputGestureCollection { new KeyGesture(Key.Left, ModifierKeys.None, "Left Arrow") }); SelectNext = new RoutedUICommand("Restore window", "Restore", typeof(SelectorCommands), new InputGestureCollection { new KeyGesture(Key.Right, ModifierKeys.None, "Right Arrow") }); }
public MainWindow() { InitializeComponent(); ObservableCollection <String> lst = new ObservableCollection <string>(); lst.Add("jen"); lst.Add("dva"); lst.Add("tri"); dg.ItemsSource = lst; RoutedUICommand komanda = new RoutedUICommand(); CommandBinding cb = new CommandBinding(); cb.Executed += Foo; cb.CanExecute += Test; cb.Command = komanda; dugme.Command = komanda; dugme.CommandTarget = dg; dugme.CommandParameter = lst; this.CommandBindings.Add(cb); }
static MainWindow() { DefaultStyleKeyProperty.OverrideMetadata(typeof(MainWindow), new FrameworkPropertyMetadata(typeof(MainWindow))); // We implement some elementary commands. // The shortcuts specified, are the same as in Chrome. OpenInTab = new RoutedUICommand( Properties.Resources.OpenInNewTab, "OpenInTab", typeof(MainWindow), new InputGestureCollection(new KeyGesture[] { new KeyGesture(Key.Enter, ModifierKeys.Control) })); OpenInWindow = new RoutedUICommand( Properties.Resources.OpenInNewWindow, "OpenInWindow", typeof(MainWindow), new InputGestureCollection(new KeyGesture[] { new KeyGesture(Key.Enter, ModifierKeys.Shift) })); NewTab = new RoutedUICommand( Properties.Resources.NewTab, "NewTab", typeof(MainWindow), new InputGestureCollection(new KeyGesture[] { new KeyGesture(Key.T, ModifierKeys.Control) })); CloseTab = new RoutedUICommand( Properties.Resources.CloseTab, "CloseTab", typeof(MainWindow), new InputGestureCollection(new KeyGesture[] { new KeyGesture(Key.W, ModifierKeys.Control) })); ShowDownloads = new RoutedUICommand( Properties.Resources.Downloads, "ShowDownloads", typeof(MainWindow)); ShowSettings = new RoutedUICommand( Properties.Resources.Settings, "ShowSettings", typeof(MainWindow)); OpenSource = new RoutedUICommand( Properties.Resources.ShowSource, "OpenSource", typeof(MainWindow)); }
void InitializeSplitCommandBinding() { HorizontalSplitCommand = new RoutedUICommand("Horizontal Split", "HorizontalSplit", typeof(EventPolygon)); horizontalSplitCommandBinding = new CommandBinding( HorizontalSplitCommand, HorizontalSplitExecuted, HorizontalSplitCanExecute); Polygon.CommandBindings.Add(horizontalSplitCommandBinding); Polygon.InputBindings.Add( new MouseBinding(HorizontalSplitCommand, new MouseGesture(MouseAction.LeftClick, ModifierKeys.Alt))); VerticalSplitCommand = new RoutedUICommand("Vertical Split", "VerticalSplit", typeof(EventPolygon)); verticalSplitCommandBinding = new CommandBinding( VerticalSplitCommand, VerticalSplitExecuted, VerticalSplitCanExecute); Polygon.CommandBindings.Add(verticalSplitCommandBinding); Polygon.InputBindings.Add( new MouseBinding(VerticalSplitCommand, new MouseGesture(MouseAction.LeftClick, ModifierKeys.Control | ModifierKeys.Alt))); }
static CustomCommands() { Exit = new RoutedUICommand( "Exit", nameof(Exit), typeof(CustomCommands)); Exit.InputGestures.Add(new KeyGesture(Key.F4, ModifierKeys.Alt)); Encrypt = new RoutedUICommand( "Encrypt", nameof(Encrypt), typeof(CustomCommands)); Encrypt.InputGestures.Add(new KeyGesture(Key.E, ModifierKeys.Control)); Decrypt = new RoutedUICommand( "Decrypt", nameof(Decrypt), typeof(CustomCommands)); Decrypt.InputGestures.Add(new KeyGesture(Key.D, ModifierKeys.Control)); Sign = new RoutedUICommand( "Sign", nameof(Sign), typeof(CustomCommands)); Sign.InputGestures.Add(new KeyGesture(Key.S, ModifierKeys.Control)); Check = new RoutedUICommand( "Check", nameof(Check), typeof(CustomCommands)); Check.InputGestures.Add(new KeyGesture(Key.C, ModifierKeys.Control)); }
private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e) { RoutedUICommand cmd = (RoutedUICommand)e.Command; temp.Text = string.Format("{0} ({1})\n{2}", cmd.Name, e.Parameter, temp.Text); if (cmd == VISCACommands.Pan) { _lastPanCmd = (int)e.Parameter; } else if (cmd == VISCACommands.Tilt) { _lastTiltCmd = (int)e.Parameter; } else if (cmd == VISCACommands.Zoom) { _lastZoom = (int)e.Parameter; } }
static ClientCommands() { ToggleFullScreen = new RoutedUICommand("Toggle Full Screen", "ToggleFullScreen", typeof(ClientCommands), new InputGestureCollection() { new KeyGesture(Key.F11) }); OpenConsoleCommand = new RoutedUICommand("Open Console", "OpenConsole", typeof(ClientCommands), new InputGestureCollection() { new KeyGesture(Key.Enter, ModifierKeys.Control) }); OpenFocusDebugCommand = new RoutedUICommand("Open FocusDebug", "OpenFocusDebug", typeof(ClientCommands)); Open3DDebugCommand = new RoutedUICommand("Open 3D Debug", "Open3DDebug", typeof(ClientCommands), new InputGestureCollection() { new KeyGesture(Key.D, ModifierKeys.Control) }); }
private static bool GetSystemGestureText(RoutedUICommand Command, FrameworkElement Source, out string DisplayString) { IGestureSource AsGestureSource; if ((AsGestureSource = Source as IGestureSource) != null) { IGestureTranslator Translator = AsGestureSource.GestureTranslator; if (Translator != null) { foreach (InputGesture Gesture in Command.InputGestures) { if (GestureToText(Gesture, Translator, out DisplayString)) { return(true); } } } } DisplayString = null; return(false); }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { RoutedUICommand command = value as RoutedUICommand; InputGestureCollection col = command?.InputGestures; if (col != null && (col.Count >= 1)) { // Search for the first key gesture for (int i = 0; i < col.Count; i++) { KeyGesture keyGesture = ((IList)col)[i] as KeyGesture; if (keyGesture != null) { return(String.Format("{0}\n({1})", command.Text, keyGesture.GetDisplayStringForCulture(CultureInfo.CurrentCulture))); } } } return(Binding.DoNothing); }
// Return the base without the AccessKey character /// override protected string GetNameCore() { string result = base.GetNameCore(); ButtonBase bb = (ButtonBase)Owner; if (!string.IsNullOrEmpty(result)) { if (bb.Content is string) { result = AccessText.RemoveAccessKeyMarker(result); } } else { RoutedUICommand uiCommand = bb.Command as RoutedUICommand; if (uiCommand != null && !string.IsNullOrEmpty(uiCommand.Text)) { result = uiCommand.Text; } } return(result); }
static DesktopCommands() { clear = CreateCommand("Clear", typeof(DesktopCommands), Key.C, ModifierKeys.Alt, "Alt+C"); loginfo = CreateCommand("LogInfo", typeof(DesktopCommands), Key.L, ModifierKeys.Control, "Ctrl+L"); import = CreateCommand("Import", typeof(DesktopCommands), Key.I, ModifierKeys.Control, "Ctrl+I"); runconsole = CreateCommand("RunConsole", typeof(DesktopCommands), Key.D, ModifierKeys.Control, "Ctrl+D"); //Export Comand export = CreateCommand("Export", typeof(DesktopCommands), Key.E, ModifierKeys.Control, "Ctrl+E"); //StartView Command startview = CreateCommand("StartView", typeof(DesktopCommands), Key.N, ModifierKeys.Control | ModifierKeys.Shift, "Ctrl+Shift+N"); //About Command about = new RoutedUICommand("About", "About", typeof(DesktopCommands)); about.InputGestures.Add(new KeyGesture(Key.A, ModifierKeys.Alt, "Alt+A")); //SaveAs Command saveas = new RoutedUICommand("SaveAs", "SaveAs", typeof(DesktopCommands)); saveas.InputGestures.Add(new KeyGesture(Key.S, ModifierKeys.Control | ModifierKeys.Shift, "Ctrl+Shift+S")); //Quit Commmand quit = CreateCommand("Quit", typeof(DesktopCommands), Key.Q, ModifierKeys.Control, "Ctrl+Q"); zoomin = new RoutedUICommand("ZoomIn", "ZoomIn", typeof(DesktopCommands)); zoomin.InputGestures.Add(new KeyGesture(Key.OemPlus, ModifierKeys.Control, "Ctrl+")); zoomout = new RoutedUICommand("ZoomOut", "ZoomOut", typeof(DesktopCommands)); zoomout.InputGestures.Add(new KeyGesture(Key.OemMinus, ModifierKeys.Control, "Ctrl-")); //Snip Command snips = new RoutedUICommand("Snips", "Snips", typeof(DesktopCommands)); snips.InputGestures.Add(new KeyGesture(Key.Space, ModifierKeys.Control)); }