/// <summary> /// Binds a Command to an Input Binding. /// </summary> /// <typeparam name="TViewModel"> /// The ViewModel that the command is in. /// </typeparam> /// <typeparam name="TView"> /// The view that the input binding is in. /// </typeparam> /// <typeparam name="TVMCmd"> /// The Command. /// </typeparam> /// <param name="view"> /// The view that the input binding is in. /// </param> /// <param name="viewModel"> /// The ViewModel that the command is in. /// </param> /// <param name="vmCmd"> /// The command that fires when the hotkey is pressed. /// </param> /// <param name="gesture"> /// The hotkey input gesture that activates the command. /// </param> public static void BindHotkey <TViewModel, TView, TVMCmd>(this TView view, TViewModel viewModel, Expression <Func <TViewModel, TVMCmd> > vmCmd, InputGesture gesture) where TViewModel : class where TView : UIElement, IViewFor where TVMCmd : class, ICommand { TVMCmd command = vmCmd.Compile().Invoke(viewModel); switch (gesture) { case KeyGesture key: { KeyBinding binding = new KeyBinding(command, key); view.InputBindings.Add(binding); break; } case MouseGesture mouse: { MouseBinding binding = new MouseBinding(command, mouse); view.InputBindings.Add(binding); break; } default: { throw new NotImplementedException(); } } }
private static void AddMouseBindings(UIElement element) { MouseAction mouseCommandAction = MouseCommands.GetMouseCommandAction(element); MouseBinding mouseBinding1 = new MouseBinding(); mouseBinding1.Gesture = (InputGesture) new MouseGesture(mouseCommandAction, ModifierKeys.None); mouseBinding1.Command = (ICommand)MouseCommands.KeyboardModifierChain.Instance; mouseBinding1.CommandParameter = (object)element; MouseBinding mouseBinding2 = mouseBinding1; element.InputBindings.Add((InputBinding)mouseBinding2); MouseBinding mouseBinding3 = new MouseBinding(); mouseBinding3.Gesture = (InputGesture) new MouseGesture(mouseCommandAction, ModifierKeys.Control); mouseBinding3.Command = (ICommand)MouseCommands.KeyboardModifierChain.Instance; mouseBinding3.CommandParameter = (object)element; MouseBinding mouseBinding4 = mouseBinding3; element.InputBindings.Add((InputBinding)mouseBinding4); MouseBinding mouseBinding5 = new MouseBinding(); mouseBinding5.Gesture = (InputGesture) new MouseGesture(mouseCommandAction, ModifierKeys.Shift); mouseBinding5.Command = (ICommand)MouseCommands.KeyboardModifierChain.Instance; mouseBinding5.CommandParameter = (object)element; MouseBinding mouseBinding6 = mouseBinding5; element.InputBindings.Add((InputBinding)mouseBinding6); }
/// <summary> /// Set the preview pane to a previewable item /// </summary> /// <param name="item"></param> public void SetPreviewItem(object item) { if (item is Thumbnail) { // Set the underlying object's preview then add a context menu Thumbnail thumb = (Thumbnail)item; SetPreviewItem(thumb.ThumbnailOf); } else if (item is BitmapType) { BitmapType preview = (BitmapType)item; imagePreview.Source = preview.Bitmap; InputBindings.Clear(); MouseBinding doubleclick = new MouseBinding(Commands.CmdFullscreen, new MouseGesture(MouseAction.LeftDoubleClick)); doubleclick.CommandTarget = this; doubleclick.CommandParameter = preview; InputBindings.Add(doubleclick); List <MenuItem> menuitems = GetMenuItems(item, item); ContextMenu = new ContextMenu() { ItemsSource = menuitems }; } else { imagePreview.Source = null; InputBindings.Clear(); ContextMenu = null; } }
private void CreateMouseBinding(object sender, MouseEventArgs e) { var mouseBind = new MouseBinding { Property = ParseMouseButton(e) }; Return(mouseBind); }
private static void GenerateInputBindings(CodeMemberMethod method, FrameworkElement element) { for (int i = 0; i < element.InputBindings.Count; i++) { CodeVariableDeclarationStatement bindingVar = null; string bindingVarName = element.Name + "_IB_" + i; var bindingVarRef = new CodeVariableReferenceExpression(bindingVarName); MouseBinding mouseBinding = element.InputBindings[i] as MouseBinding; if (mouseBinding != null) { bindingVar = new CodeVariableDeclarationStatement("MouseBinding", bindingVarName, new CodeObjectCreateExpression("MouseBinding")); method.Statements.Add(bindingVar); MouseGesture mouseGesture = mouseBinding.Gesture as MouseGesture; if (mouseGesture != null) { method.Statements.Add(new CodeAssignStatement( new CodeFieldReferenceExpression(bindingVarRef, "Gesture"), new CodeObjectCreateExpression("MouseGesture", new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(typeof(MouseAction).Name), mouseGesture.MouseAction.ToString()), new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(typeof(ModifierKeys).Name), mouseGesture.Modifiers.ToString()) ))); } } KeyBinding keyBinding = element.InputBindings[i] as KeyBinding; if (keyBinding != null) { bindingVar = new CodeVariableDeclarationStatement("KeyBinding", bindingVarName, new CodeObjectCreateExpression("KeyBinding")); method.Statements.Add(bindingVar); KeyGesture keyGesture = keyBinding.Gesture as KeyGesture; if (keyGesture != null) { method.Statements.Add(new CodeAssignStatement( new CodeFieldReferenceExpression(bindingVarRef, "Gesture"), new CodeObjectCreateExpression("KeyGesture", new CodeFieldReferenceExpression(new CodeTypeReferenceExpression("KeyCode"), keyGesture.Key.ToString()), new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(typeof(ModifierKeys).Name), keyGesture.Modifiers.ToString()), new CodePrimitiveExpression(keyGesture.DisplayString) ))); } } if (bindingVar != null) { DependencyObject depObject = element.InputBindings[i] as DependencyObject; CodeComHelper.GenerateField <object>(method, bindingVarRef, depObject, InputBinding.CommandParameterProperty); CodeComHelper.GenerateBindings(method, bindingVarRef, depObject, bindingVarName); method.Statements.Add(new CodeMethodInvokeExpression( new CodeVariableReferenceExpression(element.Name), "InputBindings.Add", new CodeVariableReferenceExpression(bindingVarName))); } } }
public static TUiElement MouseBinding <TUiElement>(this TUiElement @this, MouseAction mouseAction, out MouseBinding mouseBinding) where TUiElement : UIElement { mouseBinding = new MouseBinding { MouseAction = mouseAction }; @this.InputBindings.Add(mouseBinding); return(@this); }
public static TUiElement MouseBinding <TUiElement>(this TUiElement @this, MouseAction mouseAction, ICommand command) where TUiElement : UIElement { var mouseBinding = new MouseBinding { MouseAction = mouseAction, Command = command }; @this.InputBindings.Add(mouseBinding); return(@this); }
public static TUiElement MouseBinding <TUiElement>(this TUiElement @this, MouseAction mouseAction, Action <MouseBinding> applyFunc) where TUiElement : UIElement { var mouseBinding = new MouseBinding { MouseAction = mouseAction }; applyFunc(mouseBinding); @this.InputBindings.Add(mouseBinding); return(@this); }
public CustomGrid(ViewModel model) { tb = new TextBlock(); tb.Text = "hello world"; Children.Add(tb); // just to show something Background = new SolidColorBrush(Colors.LightGray); DataContext = model; var binding = new MouseBinding(ViewModel.ClickCommand, new MouseGesture(MouseAction.LeftClick)); InputBindings.Add(binding); var commandBinding = new CommandBinding(ViewModel.ClickCommand, SelectElementExecute); CommandBindings.Add(commandBinding); }
private void PrepararImagemDeCompraDeCartas() { Image img = ObterImagem("cartasCompra.png"); img.Width = 130; _imagemDeExemplo = img; MouseGesture cmdMouseGesture = new MouseGesture(MouseAction.LeftClick, ModifierKeys.None); MouseBinding cmdMouseBinding = new MouseBinding(PedirCartaCommand, cmdMouseGesture); img.InputBindings.Add(cmdMouseBinding); _stackCompraCartas.Children.Add(img); }
private static void LeftDoubleClickChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args) { var control = (Control)sender; if (args.NewValue != null && args.NewValue is ICommand) { var newBinding = new MouseBinding(args.NewValue as ICommand, new MouseGesture(MouseAction.LeftDoubleClick)); control.InputBindings.Add(newBinding); } else { var oldBinding = control.InputBindings.Cast <InputBinding>().First(b => b.Command.Equals(args.OldValue)); control.InputBindings.Remove(oldBinding); } }
///////////////////////////////////////////////////////////////////////////////////////////////////// // NON-PUBLIC PROCEDURES ///////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Handles the <c>Checked</c> event of the <see cref="logoRadioButton"/> or <see cref="buttonRadioButton"/> control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param> private void OnRadioButtonChecked(object sender, RoutedEventArgs e) { if (null == this.zoomContentControl) { return; } // Remove the MouseBinding that is bound to the LeftClick action for (int i = 0; i < this.zoomContentControl.InputBindings.Count; i++) { MouseBinding binding = this.zoomContentControl.InputBindings[i] as MouseBinding; if (null != binding) { MouseGesture gesture = binding.Gesture as MouseGesture; if (null != gesture && MouseAction.LeftClick == gesture.MouseAction && ModifierKeys.None == gesture.Modifiers) { this.zoomContentControl.InputBindings.RemoveAt(i); break; } } } // Add in a new MouseBinding for the LeftClick action this.zoomContentControl.InputBindings.Clear(); if (true == this.panDragRadioButton.IsChecked) { this.zoomContentControl.InputBindings.Add(new MouseBinding(ZoomContentControlCommands.StartPanDrag, new MouseGesture(MouseAction.LeftClick))); } else if (true == this.zoomInRadioButton.IsChecked) { this.zoomContentControl.InputBindings.Add(new MouseBinding(ZoomContentControlCommands.StartZoomIn, new MouseGesture(MouseAction.LeftClick))); } else if (true == this.zoomOutRadioButton.IsChecked) { this.zoomContentControl.InputBindings.Add(new MouseBinding(ZoomContentControlCommands.StartZoomOut, new MouseGesture(MouseAction.LeftClick))); } else if (true == this.zoomDragRadioButton.IsChecked) { this.zoomContentControl.InputBindings.Add(new MouseBinding(ZoomContentControlCommands.StartZoomDrag, new MouseGesture(MouseAction.LeftClick))); } this.zoomContentControl.UpdateCursor(); }
private void LedMatrixInit() { BrushConverter bc = new BrushConverter(); int[] ledColors = InitialColors; Grid grid = new Grid() { HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center }; for (int i = 0; i < 8; i++) { grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); for (int j = 0; j < 8; j++) { grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto }); Rectangle rect = new Rectangle() { Fill = new SolidColorBrush(Color.FromArgb(153, (byte)((ledColors[i * 8 + j] >> 16) & 0xFF), (byte)((ledColors[i * 8 + j] >> 8) & 0xFF), (byte)((ledColors[i * 8 + j] >> 0) & 0xFF))), Width = 30, Height = 30, Margin = new Thickness(5, 5, 5, 5), }; LedClicked = new LedCommand(this, i, j); MouseAction action = MouseAction.LeftClick; MouseGesture gesture = new MouseGesture(action); MouseBinding binding = new MouseBinding(LedClicked, gesture); rect.InputBindings.Add(binding); Grid.SetRow(rect, i); Grid.SetColumn(rect, j); grid.Children.Add(rect); ledMatrix.Add(Tuple.Create(i, j), rect); ledMatrixData[i * 8 + j] = initialColor; } } ViewLedMatrix = grid; }
private void addEllipseClick() { foreach (string s in nodeList) { object obj = _xaml.FindName(s); if (!(obj is Ellipse)) { throw new XamlParseException($"{s} is Not a Ellipse."); } Ellipse ellipse = (Ellipse)obj; MouseGesture gesture = new MouseGesture(MouseAction.LeftClick); MouseBinding binding = new MouseBinding(new NodeClickCommand(), gesture); binding.CommandParameter = new Tuple <ScenicMap, Ellipse>(this, ellipse); ellipse.InputBindings.Add(binding); } }
private Image ObterImagemDaCarta(Carta carta, string commandParameterName) { Image novaCarta = ObterImagem($"{carta.Simbolo.ToString().ToLower()}{carta.Nipe}.png"); novaCarta.Width = 90; string nomeDoCommandParameter = commandParameterName; novaCarta.Name = $"carta{nomeDoCommandParameter}_{carta.Simbolo.ToString().ToLower()}_{carta.Nipe}"; novaCarta.Margin = new Thickness(10, 0, 0, 0); MouseGesture mouseGesture = new MouseGesture(MouseAction.LeftClick, ModifierKeys.None); MouseBinding mouseBinding = new MouseBinding(SelectCardCommand, mouseGesture); mouseBinding.CommandParameter = novaCarta; novaCarta.InputBindings.Add(mouseBinding); return(novaCarta); }
private static void SelectedItemDoubleClickedCommandAttachedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var item = d as TreeViewItem; if (item != null) { if (e.NewValue != null) { var binding = new MouseBinding((ICommand)e.NewValue, new MouseGesture(MouseAction.LeftDoubleClick)); BindingOperations.SetBinding(binding, InputBinding.CommandParameterProperty, new Binding("SelectedItem") { RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(TreeView), 1) }); item.InputBindings.Add(binding); } } }
public Hotkeys(MainWindow parentwindow, ProgramSettings settings) { programSettings = settings; parent = parentwindow; InitializeComponent(); rightClickGesture.MouseAction = MouseAction.RightClick; MouseBinding rightClickBinding = new MouseBinding(); RoutedCommand rightClickCmd = new RoutedCommand(); rightClickBinding.Gesture = rightClickGesture; rightClickBinding.Command = rightClickCmd; CommandBinding rightClickCmdBinding = new CommandBinding(); rightClickCmdBinding.Command = rightClickCmd; rightClickCmdBinding.Executed += Button_RightClick; Uri uri = new Uri("pack://application:,,,/B_32x32.ico", UriKind.RelativeOrAbsolute); this.Icon = BitmapFrame.Create(uri); for (int i = 0; i < programSettings.NumHotKeys; i++) { Button btn = new Button(); btn.Name = "btn" + i.ToString(); btn.Click += Button_Click; btn.Width = 56; btn.InputBindings.Add(rightClickBinding); btn.CommandBindings.Add(rightClickCmdBinding); pnlButtons.Children.Add(btn); if (programSettings.HotkeyCommands.Count <= i) { Alias alias = new Alias(); alias.Keyword = "(None)"; btn.Content = "(none)"; alias.Expansion = String.Empty; programSettings.HotkeyCommands.Add(alias); } else { btn.Content = programSettings.HotkeyCommands[i].Keyword; } } }
public FullscreenView(object item, CloseDelegate OnClose) { InitializeComponent(); theItem = item; this.CommandBindings.Add(new CommandBinding(Commands.CmdFullscreenClose, CmdFullscreenCloseExecuted, CmdFullscreenCloseCanExecute)); // Close with double-click MouseBinding doubleclick = new MouseBinding(Commands.CmdFullscreenClose, new MouseGesture(MouseAction.LeftDoubleClick)); doubleclick.CommandTarget = this; InputBindings.Add(doubleclick); previewFullScreen.InputBindings.Add(doubleclick); previewFullScreen.imagePreview.InputBindings.Add(doubleclick); // Close with Escape... want to close on any key really, so might as well use the old-fashioned keydown event InputBindings.Add(new KeyBinding(Commands.CmdFullscreenClose, new KeyGesture(Key.Escape))); // Handler for closing this.OnClose = OnClose; }
private static void RefreshMouseBinding(UIElement element) { if (!MouseCommands.HasMouseCommand(element)) { return; } bool flag = false; foreach (InputBinding inputBinding in element.InputBindings) { MouseBinding mouseBinding = inputBinding as MouseBinding; if (mouseBinding != null) { MouseCommands.UpdateMouseBinding(element, mouseBinding); flag = true; } } if (flag) { return; } MouseCommands.AddMouseBindings(element); }
public override void SetBindings() { //Use InputBindings to handle mouse interactions // MouseAction.LeftClick // MouseAction.LeftDoubleClick // MouseAction.MiddleClick // MouseAction.MiddleDoubleClick // MouseAction.None // MouseAction.RightClick // MouseAction.RightDoubleClick // MouseAction.WheelClick doubleClickMouseBinding = new MouseBinding(DisplayTextBox, new MouseGesture(MouseAction.LeftDoubleClick)) { CommandParameter = this }; displayTextBoxCommandBinding = new CommandBinding(DisplayTextBox, DisplayTextBoxExecuted); if (UiWrapper != null) { UiWrapper.InputBindings.Add(doubleClickMouseBinding); UiWrapper.CommandBindings.Add(displayTextBoxCommandBinding); UiWrapper.Children.Add(tbNotes); } }
protected override void OnAttached() { doubleClickMouseBinding = new MouseBinding( new Command(() => { canDragFromMaximized = false; AssociatedWindow.WindowState = AssociatedWindow.WindowState != WindowState.Maximized ? WindowState.Maximized : WindowState.Normal; }), new MouseGesture(MouseAction.LeftDoubleClick)); base.OnAttached(); registeredToStateChanged = false; canDragFromMaximized = false; AssociatedObject.MouseLeftButtonDown += OnMouseLeftButtonDown; AssociatedObject.MouseMove += OnMouseMove; AssociatedObject.MouseEnter += OnMouseEnter; AssociatedObject.InputBindings.Add(doubleClickMouseBinding); }
/// <summary> /// Initializes a new instance of the <see cref="T:M138ADemo.MainSettings"/> class. /// </summary> public MainSettings() { InitializeComponent(); viewModel = new MainSettingsViewModel(); mExtendedWorkspaceRadioButton.SetBinding(RadioButton.IsCheckedProperty, new Binding() { Source = viewModel, Path = new PropertyPath("IsCheckedExtendedWorkspace"), Mode = BindingMode.TwoWay, NotifyOnSourceUpdated = true, }); // mExtendedWorkspaceRadioButton.Command = viewModel.OnExtendedWorkspaceButtonCommand; viewModel.OnSaveHappend += (flag) => { if (Configuration.Encrypt) { AddKeys w = new AddKeys(); w.Show(); } else { DecryptAddKeys w = new DecryptAddKeys(); w.Show(); } if (flag) { this.Close(); } }; viewModel.OnOpenFileHappend += (filePath) => { DragAndDrop w = new DragAndDrop(); w.CurrentFilePath = filePath; w.Show(); this.Close(); }; viewModel.OnOpenRecentFileHappend += (filePath) => { DragAndDrop w = new DragAndDrop(); w.CurrentFilePath = filePath; w.Show(); this.Close(); }; //mMessagetextBox.TextChanged += MMessagetextBox_TextChanged; Binding binding = new Binding() { Mode = BindingMode.TwoWay, Source = viewModel.Model, Path = new PropertyPath("Message"), NotifyOnSourceUpdated = true, NotifyOnTargetUpdated = true, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }; mNextButton.DataContext = viewModel; Binding enableBinding = new Binding() { Mode = BindingMode.TwoWay, Path = new PropertyPath("isNextButtonEnabled"), NotifyOnSourceUpdated = true, NotifyOnTargetUpdated = true, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }; Binding colorBinding = new Binding() { Mode = BindingMode.OneWay, Path = new PropertyPath("NextButtonColor"), NotifyOnSourceUpdated = true, NotifyOnTargetUpdated = true, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }; Binding decryptBinding = new Binding() { Mode = BindingMode.TwoWay, Source = viewModel.Model, Path = new PropertyPath("Encrypt"), NotifyOnTargetUpdated = true, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, Converter = new InverseBoolConverter() }; Binding encryptBinding = new Binding() { Mode = BindingMode.TwoWay, Source = viewModel.Model, Path = new PropertyPath("Encrypt"), NotifyOnTargetUpdated = true, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }; Binding automaticBinding = new Binding() { Mode = BindingMode.TwoWay, Source = viewModel.Model, Path = new PropertyPath("Automatic"), NotifyOnTargetUpdated = true, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }; Binding manualBinding = new Binding() { Mode = BindingMode.TwoWay, Source = viewModel.Model, Path = new PropertyPath("Automatic"), NotifyOnTargetUpdated = true, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, Converter = new InverseBoolConverter() }; { var mouseBinding = new MouseBinding(this.viewModel.OnLabelClickCommand, new MouseGesture(MouseAction.LeftClick)); mouseBinding.CommandParameter = MainSettingsViewModel.LabelClicks.Encrypt; mEncryptLabel.InputBindings.Add(mouseBinding); } { var mouseBinding = new MouseBinding(this.viewModel.OnLabelClickCommand, new MouseGesture(MouseAction.LeftClick)); mouseBinding.CommandParameter = MainSettingsViewModel.LabelClicks.Decrypt; mDecrypttLabel.InputBindings.Add(mouseBinding); } { var mouseBinding = new MouseBinding(this.viewModel.OnLabelClickCommand, new MouseGesture(MouseAction.LeftClick)); mouseBinding.CommandParameter = MainSettingsViewModel.LabelClicks.Automatic; mAutomaticLabel.InputBindings.Add(mouseBinding); } { var mouseBinding = new MouseBinding(this.viewModel.OnLabelClickCommand, new MouseGesture(MouseAction.LeftClick)); mouseBinding.CommandParameter = MainSettingsViewModel.LabelClicks.Manual; mManualLabel.InputBindings.Add(mouseBinding); } { var mouseBinding = new MouseBinding(this.viewModel.OnLabelClickCommand, new MouseGesture(MouseAction.LeftClick)); mouseBinding.CommandParameter = MainSettingsViewModel.LabelClicks.ExtendedWorkspace; mExtendedWorkspaceLabel.InputBindings.Add(mouseBinding); } mDecrypt.SetBinding(RadioButton.IsCheckedProperty, decryptBinding); mEncrypt.SetBinding(RadioButton.IsCheckedProperty, encryptBinding); mNextButton.SetBinding(Button.BackgroundProperty, colorBinding); mNextButton.SetBinding(Button.IsEnabledProperty, enableBinding); mMessagetextBox.SetBinding(TextBox.TextProperty, binding); mManualRadioButtom.SetBinding(RadioButton.IsCheckedProperty, manualBinding); mAutomaticRadioButton.SetBinding(RadioButton.IsCheckedProperty, automaticBinding); mNextButton.Command = viewModel.SaveToSettingsCommand; mAutomaticRadioButton.IsChecked = true; //mNextButton.Click += mNextButtonOnClick; mEncrypt.IsChecked = true; //Configuration.Message = mMessagetextBox.Text; //mNextButton.IsEnabled = false; //mNextButton.Background = Brushes.LightGray; //mOpenMenuItem.Click += MOpenMenuItem_Click; mOpenMenuItem.Command = viewModel.OpenFileCommand; RecentFiles.MachineStatesShared.LoadFilesFromDisk(); RecentFiles.KeysCollectionShared.LoadFilesFromDisk(); //mOpenRecentsMenuItem.ItemsSource = RecentFiles.MachineStatesShared.ShortenedNamesMenuItems; mOpenRecentsMenuItem.DataContext = RecentFiles.MachineStatesShared; mOpenRecentsMenuItem.ItemsSource = RecentFiles.MachineStatesShared.ShortenedNamesMenuItems; RecentFiles.MachineStatesShared.PropertyChanged += MachineStatesShared_PropertyChanged; mOpenDocsMenuItem.Command = viewModel.OpenDocsCommand; SetMenuItemsCommands(); }
/// <summary> /// Add a MouseButton binding that can be checked for state (Pressed, Released, Active) /// </summary> public static bool AddBinding(this InputManager inputManager, string bindingName, MouseButton mouseButton, params InputBinding[] modifiers) { DefaultBinding inputBinding = new MouseBinding(mouseButton, modifiers); return inputManager.AddBinding(bindingName, inputBinding); }
// </SnippetKeyGestureGetProperties> private void OnLoaded(object sender, RoutedEventArgs e) { // <SnippetKeyBindingKeyGestureSetProperties> // Defining the KeyGesture. KeyGesture FindCmdKeyGesture = new KeyGesture(Key.F, (ModifierKeys.Shift | ModifierKeys.Alt)); // Defining the KeyBinding. KeyBinding FindKeyBinding = new KeyBinding( ApplicationCommands.Find, FindCmdKeyGesture); // Binding the KeyBinding to the Root Window. this.InputBindings.Add(FindKeyBinding); // </SnippetKeyBindingKeyGestureSetProperties> // <SnippetKeyBindingWithNoModifier> KeyGesture OpenCmdKeyGesture = new KeyGesture(Key.F12); KeyBinding OpenKeyBinding = new KeyBinding( ApplicationCommands.Open, OpenCmdKeyGesture); this.InputBindings.Add(OpenKeyBinding); // </SnippetKeyBindingWithNoModifier> // <SnippetKeyBindingWithKeyAndModifiers> KeyGesture CloseCmdKeyGesture = new KeyGesture( Key.L, ModifierKeys.Alt); KeyBinding CloseKeyBinding = new KeyBinding( ApplicationCommands.Close, CloseCmdKeyGesture); this.InputBindings.Add(CloseKeyBinding); // </SnippetKeyBindingWithKeyAndModifiers> // <SnippetKeyBindingMultipleModifiers> KeyBinding CopyKeyBinding = new KeyBinding( ApplicationCommands.Copy, Key.D, (ModifierKeys.Control | ModifierKeys.Shift)); this.InputBindings.Add(CopyKeyBinding); // </SnippetKeyBindingMultipleModifiers> // <SnippetKeyBindingDefatulCtor> KeyBinding RedoKeyBinding = new KeyBinding(); RedoKeyBinding.Modifiers = ModifierKeys.Alt; RedoKeyBinding.Key = Key.F; RedoKeyBinding.Command = ApplicationCommands.Redo; this.InputBindings.Add(RedoKeyBinding); // </SnippetKeyBindingDefatulCtor> // <SnippetMouseBindingAddedToInputBinding> MouseGesture OpenCmdMouseGesture = new MouseGesture(); OpenCmdMouseGesture.MouseAction = MouseAction.WheelClick; OpenCmdMouseGesture.Modifiers = ModifierKeys.Control; MouseBinding OpenCmdMouseBinding = new MouseBinding(); OpenCmdMouseBinding.Gesture = OpenCmdMouseGesture; OpenCmdMouseBinding.Command = ApplicationCommands.Open; this.InputBindings.Add(OpenCmdMouseBinding); // </SnippetMouseBindingAddedToInputBinding> // <SnippetMouseBindingAddedCommand> MouseGesture PasteCmdMouseGesture = new MouseGesture( MouseAction.MiddleClick, ModifierKeys.Alt); ApplicationCommands.Paste.InputGestures.Add(PasteCmdMouseGesture); // </SnippetMouseBindingAddedCommand> KeyGesture pasteBind = new KeyGesture(Key.V, ModifierKeys.Alt); ApplicationCommands.Paste.InputGestures.Add(pasteBind); // <SnippetInputBindingAddingComand> KeyGesture HelpCmdKeyGesture = new KeyGesture(Key.H, ModifierKeys.Alt); InputBinding inputBinding; inputBinding = new InputBinding(ApplicationCommands.Help, HelpCmdKeyGesture); this.InputBindings.Add(inputBinding); // </SnippetInputBindingAddingComand> // <SnippetMouseBindingMouseAction> MouseGesture CutCmdMouseGesture = new MouseGesture( MouseAction.MiddleClick); MouseBinding CutMouseBinding = new MouseBinding( ApplicationCommands.Cut, CutCmdMouseGesture); // RootWindow is an instance of Window. RootWindow.InputBindings.Add(CutMouseBinding); // </SnippetMouseBindingMouseAction> // <SnippetMouseBindingGesture> MouseGesture NewCmdMouseGesture = new MouseGesture(); NewCmdMouseGesture.Modifiers = ModifierKeys.Alt; NewCmdMouseGesture.MouseAction = MouseAction.MiddleClick; MouseBinding NewMouseBinding = new MouseBinding(); NewMouseBinding.Command = ApplicationCommands.New; NewMouseBinding.Gesture = NewCmdMouseGesture; // RootWindow is an instance of Window. RootWindow.InputBindings.Add(NewMouseBinding); // </SnippetMouseBindingGesture> }
public override void OnApplyTemplate() { base.OnApplyTemplate(); PanelHost = Template.FindName("PART_PanelHost", this) as FrameworkElement; if (PanelHost != null) { var mBinding = new MouseBinding(mainModel.StartGameCommand, new MouseGesture(MouseAction.LeftDoubleClick)); BindingTools.SetBinding(mBinding, MouseBinding.CommandParameterProperty, nameof(GamesCollectionViewEntry.Game)); PanelHost.InputBindings.Add(mBinding); if (!DesignerProperties.GetIsInDesignMode(this)) { PanelHost.ContextMenu = new GameMenu(mainModel) { ShowStartSection = true }; BindingTools.SetBinding(PanelHost.ContextMenu, Button.DataContextProperty, mainModel, nameof(DesktopAppViewModel.SelectedGames)); } } ImageIcon = Template.FindName("PART_ImageIcon", this) as Image; if (ImageIcon != null) { BindingTools.SetBinding(ImageIcon, Image.VisibilityProperty, mainModel.AppSettings, nameof(PlayniteSettings.ShowIconsOnList), converter: new BooleanToVisibilityConverter()); var sourceBinding = new PriorityBinding(); sourceBinding.Bindings.Add(new Binding() { Path = new PropertyPath(nameof(GamesCollectionViewEntry.DetailsListIconObjectCached)), IsAsync = mainModel.AppSettings.AsyncImageLoading, Converter = new NullToDependencyPropertyUnsetConverter(), Mode = BindingMode.OneWay }); sourceBinding.Bindings.Add(new Binding() { Path = new PropertyPath(nameof(GamesCollectionViewEntry.DefaultDetailsListIconObjectCached)), Converter = new NullToDependencyPropertyUnsetConverter(), Mode = BindingMode.OneWay }); BindingOperations.SetBinding(ImageIcon, Image.SourceProperty, sourceBinding); } ImageCover = Template.FindName("PART_ImageCover", this) as Image; if (ImageCover != null) { var sourceBinding = new PriorityBinding(); sourceBinding.Bindings.Add(new Binding() { Path = new PropertyPath(nameof(GamesCollectionViewEntry.GridViewCoverObjectCached)), IsAsync = mainModel.AppSettings.AsyncImageLoading, Converter = new NullToDependencyPropertyUnsetConverter(), Mode = BindingMode.OneWay }); sourceBinding.Bindings.Add(new Binding() { Path = new PropertyPath(nameof(GamesCollectionViewEntry.DefaultGridViewCoverObjectCached)), Converter = new NullToDependencyPropertyUnsetConverter(), Mode = BindingMode.OneWay }); BindingOperations.SetBinding(ImageCover, Image.SourceProperty, sourceBinding); } ButtonPlay = Template.FindName("PART_ButtonPlay", this) as Button; if (ButtonPlay != null) { ButtonPlay.Command = mainModel.StartGameCommand; BindingTools.SetBinding(ButtonPlay, Button.CommandParameterProperty, nameof(GamesCollectionViewEntry.Game)); } ButtonInfo = Template.FindName("PART_ButtonInfo", this) as Button; if (ButtonInfo != null) { ButtonInfo.Command = mainModel.ShowGameSideBarCommand; BindingTools.SetBinding(ButtonInfo, Button.CommandParameterProperty, string.Empty); } }
private static void UpdateMouseBinding(UIElement element, MouseBinding mouseBinding) { ((MouseGesture)mouseBinding.Gesture).MouseAction = MouseCommands.GetMouseCommandAction(element); mouseBinding.Command = (ICommand)MouseCommands.KeyboardModifierChain.Instance; mouseBinding.CommandParameter = (object)element; }