本文整理汇总了C#中System.Windows.Input.KeyGesture类的典型用法代码示例。如果您正苦于以下问题:C# KeyGesture类的具体用法?C# KeyGesture怎么用?C# KeyGesture使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
KeyGesture类属于System.Windows.Input命名空间,在下文中一共展示了KeyGesture类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PadWindow
public PadWindow()
{
InitializeComponent();
KeyGesture F5Key = new KeyGesture(Key.F5, ModifierKeys.None);
KeyBinding F5CmdKeybinding = new KeyBinding(RunRoutedCommand, F5Key);
this.InputBindings.Add(F5CmdKeybinding);
}
示例2: MainWindow
// -------------------------------
// Window operations
// -------------------------------
/// <summary>
/// (Constructor) Initializes main window and sets up shortcut keys.
/// </summary>
public MainWindow()
{
InitializeComponent();
// Bind "New" command
CommandBinding cb = new CommandBinding( commandNew , new_Executed );
KeyGesture kg = new KeyGesture( Key.N , ModifierKeys.Control );
InputBinding ib = new InputBinding( commandNew , kg );
this.CommandBindings.Add( cb );
this.InputBindings.Add( ib );
// Bind "Open" command
cb = new CommandBinding( commandOpen , open_Executed );
kg = new KeyGesture( Key.O , ModifierKeys.Control );
ib = new InputBinding( commandOpen , kg );
this.CommandBindings.Add( cb );
this.InputBindings.Add( ib );
// Bind "Save" command
cb = new CommandBinding( commandSave , save_Executed );
kg = new KeyGesture( Key.S , ModifierKeys.Control );
ib = new InputBinding( commandSave , kg );
this.CommandBindings.Add( cb );
this.InputBindings.Add( ib );
// Bind "SaveAll" command
cb = new CommandBinding( commandSaveAll , saveAll_Executed );
kg = new KeyGesture( Key.S , ModifierKeys.Alt );
ib = new InputBinding( commandSaveAll , kg );
this.CommandBindings.Add( cb );
this.InputBindings.Add( ib );
// Bind "Exit" command
cb = new CommandBinding( commandExit , exit_Executed );
kg = new KeyGesture( Key.X , ModifierKeys.Control );
ib = new InputBinding( commandExit , kg );
this.CommandBindings.Add( cb );
this.InputBindings.Add( ib );
// Bind "Delete" command
cb = new CommandBinding( commandDelete , deleteBlock_Executed );
kg = new KeyGesture( Key.Delete );
ib = new InputBinding( commandDelete , kg );
this.CommandBindings.Add( cb );
this.InputBindings.Add( ib );
// Bind "Generate Mesh" command
cb = new CommandBinding( commandGenerateMesh , generateMesh_Executed );
kg = new KeyGesture( Key.F7 );
ib = new InputBinding( commandGenerateMesh , kg );
this.CommandBindings.Add( cb );
this.InputBindings.Add( ib );
// Bind "Run Analysis" command
cb = new CommandBinding( commandRunAnalysis , run_Executed );
kg = new KeyGesture( Key.F5 );
ib = new InputBinding( commandRunAnalysis , kg );
this.CommandBindings.Add( cb );
this.InputBindings.Add( ib );
}
示例3: MWindow
public MWindow()
{
try
{
InitializeComponent();
Closing += new CancelEventHandler(MWindow_Closing);
worker.DoWork += new DoWorkEventHandler(worker_DoWork);
worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
dt.Interval = TimeSpan.FromSeconds(1);
dt.Tick += new EventHandler(dt_Tick);
foldingManager = FoldingManager.Install(textEditor.TextArea);
foldingStrategy = new XmlFoldingStrategy();
textEditor.TextChanged += new EventHandler(textEditor_TextChanged);
if (App.StartUpCommand != "" && App.StartUpCommand != null)
{
openFile(App.StartUpCommand);
}
KeyGesture renderKeyGesture = new KeyGesture(Key.F5);
KeyBinding renderCmdKeybinding = new KeyBinding(Commands.Render, renderKeyGesture);
this.InputBindings.Add(renderCmdKeybinding);
status.Text = "Ready!";
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
示例4: RegisterShortcut
/// <summary>Registers a given shortcut for a specific views and connect that shortcut with a given action.</summary>
/// <param name="viewTypes">The view types.</param>
/// <param name="gesture">The shortcut.</param>
/// <param name="command">The command.</param>
public static void RegisterShortcut(Type[] viewTypes, KeyGesture gesture, ICommand command)
{
Contract.Requires(command != null);
foreach (var type in viewTypes)
RegisterShortcut(type, gesture, command);
}
示例5: AbstractMenuItem
public AbstractMenuItem(string header, int priority, ImageSource icon = null, ICommand command = null,
KeyGesture gesture = null, bool isCheckable = false)
{
Priority = priority;
IsSeparator = false;
Header = header;
Key = header;
Command = command;
IsCheckable = isCheckable;
Icon = icon;
if (gesture != null && command != null)
{
Application.Current.MainWindow.InputBindings.Add(new KeyBinding(command, gesture));
InputGestureText = gesture.DisplayString;
}
if (isCheckable)
{
IsChecked = false;
}
if (Header == "SEP")
{
Key = "SEP" + sepCount.ToString();
Header = "";
sepCount++;
IsSeparator = true;
}
}
示例6: SetGesture
/// <summary>
/// Sets the gesture property.
/// </summary>
/// <param name="element">The element.</param>
/// <param name="value">The value.</param>
public static void SetGesture(UIElement element, KeyGesture value)
{
if (element != null)
{
element.SetValue(GestureProperty, value);
}
}
示例7: RelayCommand
/// <summary>
/// Initializes a new instance of the <see cref="RelayCommand"/> class.
/// </summary>
/// <param name="kg">The associated <see cref="KeyGesture"/>.</param>
/// <param name="registeredType">Type of the registered command.</param>
/// <param name="execute">The action to execute.</param>
/// <param name="canExecute">The predicate that determines if the command can be executed.</param>
/// <example>
/// <code><![CDATA[
/// var cmd = new RelayCommand(new KeyGesture(Key.F7), typeof(DesignerItemWithData),
/// this.CommandNameExecuted, this.CommandNameEnabled);
/// ]]>
/// </code>
/// </example>
public RelayCommand(KeyGesture kg, Type registeredType, Action<object> execute, Predicate<object> canExecute)
{
this.execute = execute;
this.canExecute = canExecute;
this.InputGestures.Add(kg);
InputBinding ib = new InputBinding(this, kg);
CommandManager.RegisterClassInputBinding(registeredType, ib);
}
示例8: CommandMenuItem
public CommandMenuItem(Command command, StandardMenuItem parent)
{
_command = command;
_keyGesture = IoC.Get<ICommandKeyGestureService>().GetPrimaryKeyGesture(_command.CommandDefinition);
_parent = parent;
_listItems = new List<StandardMenuItem>();
}
示例9: RegisterShortcut
/// <summary>
/// Registers a given shortcut for a specific views and connect that shortcut with a given action.
/// </summary>
/// <param name="viewTypes">The view types.</param>
/// <param name="gesture">The shortcut.</param>
/// <param name="command">The command.</param>
public static void RegisterShortcut(Type[] viewTypes, KeyGesture gesture, ICommand command)
{
if (command == null)
throw new ArgumentNullException(nameof(command));
foreach (var type in viewTypes)
RegisterShortcut(type, gesture, command);
}
示例10: Command
public Command(CommandDefinitionBase commandDefinition)
{
_commandDefinition = commandDefinition;
Text = commandDefinition.Text;
ToolTip = commandDefinition.ToolTip;
IconSource = commandDefinition.IconSource;
_keyGesture = commandDefinition.KeyGesture;
}
示例11: CommandToolBarItem
public CommandToolBarItem(ToolBarItemDefinition toolBarItem, Command command, IToolBar parent)
{
_toolBarItem = toolBarItem;
_command = command;
_keyGesture = IoC.Get<ICommandKeyGestureService>().GetPrimaryKeyGesture(_command.CommandDefinition);
_parent = parent;
command.PropertyChanged += OnCommandPropertyChanged;
}
示例12: TestWindow
public TestWindow()
{
this.InitializeComponent();
CommandBinding cb = new CommandBinding(MyCommand, MyCommandExecute);
this.CommandBindings.Add(cb);
KeyGesture kg = new KeyGesture(Key.Escape, ModifierKeys.Shift);
InputBinding ib = new InputBinding(MyCommand, kg);
this.InputBindings.Add(ib);
}
示例13: CreateInputGesture
/// <summary>
/// Creates the input gesture.
/// </summary>
/// <param name="element">The element.</param>
/// <param name="key">The key to listen to.</param>
/// <param name="modifierKeys">The modifier keys to listen to.</param>
/// <param name="execute">The command to execute.</param>
/// <param name="canExecute">The command to check if the main command can execute.</param>
public static void CreateInputGesture(this UIElement element, Key key, ModifierKeys modifierKeys, ExecutedRoutedEventHandler execute, CanExecuteRoutedEventHandler canExecute)
{
var command = new RoutedUICommand();
var binding = new CommandBinding(command, execute, canExecute);
var gesture = new KeyGesture(key, modifierKeys);
var keyBinding = new KeyBinding(command, gesture);
element.CommandBindings.Add(binding);
element.InputBindings.Add(keyBinding);
}
示例14: MainWindow
public MainWindow()
{
InitializeComponent();
RootFrame.NavigationService.Navigate(new Uri("/Pages/MainPage.xaml", UriKind.Relative));
var timestampCommand = new DelegateCommand(OnTimestampKeyBinding);
var timestampGesture = new KeyGesture(Key.T, ModifierKeys.Alt);
var timestampBinding = new KeyBinding(timestampCommand, timestampGesture);
InputBindings.Add(timestampBinding);
}
示例15: SaveAsMenuItemViewModel
/// <summary>
/// Initializes a new instance of the <see cref="MenuItemViewModel" /> class.
/// </summary>
/// <param name="header">The header.</param>
/// <param name="priority">The priority.</param>
/// <param name="icon">The icon.</param>
/// <param name="command">The command.</param>
/// <param name="gesture">The gesture.</param>
/// <param name="isCheckable">if set to <c>true</c> this menu acts as a checkable menu.</param>
/// <param name="hideDisabled">if set to <c>true</c> this menu is not visible when disabled.</param>
/// <param name="container">The container.</param>
public SaveAsMenuItemViewModel(string header, int priority, ImageSource icon = null, ICommand command = null,
KeyGesture gesture = null, bool isCheckable = false, bool hideDisabled = false,
IUnityContainer container = null)
: base(header, priority, icon, command, gesture, isCheckable, hideDisabled)
{
if (container != null)
{
var eventAggregator = container.Resolve<IEventAggregator>();
eventAggregator.GetEvent<ActiveContentChangedEvent>().Subscribe(SaveAs);
}
}