public EditDisplacementDoc() { InitializeComponent(); Loaded += (sender, args) => { Lines.Focus(); }; Keyboard.AddPreviewKeyDownHandler(this, (sender, args) => { IEnumerable <IResult> results = null; if (args.Key == Key.Insert) { results = Model.Add(); args.Handled = true; } else if (args.Key == Key.Delete) { Model.Delete(); args.Handled = true; } if (results != null) { Coroutine.BeginExecute(results.GetEnumerator(), new ActionExecutionContext { View = this }); args.Handled = true; } }); }
public DisplacementDocs() { InitializeComponent(); ApplyStyles(); Loaded += (sender, args) => { Items.Focus(); }; Items.CommandBindings.Add(new CommandBinding(DataGrid.DeleteCommand, Commands.DoInvokeViewModel, Commands.CanInvokeViewModel)); Keyboard.AddPreviewKeyDownHandler(this, (sender, args) => { if (args.Key == Key.Insert) { Model.Create(); args.Handled = true; } else if (args.Key == Key.Delete) { var task = Model.Delete(); args.Handled = true; } }); }
protected override void OnAttached() { Keyboard.AddPreviewKeyDownHandler(ListView, PreviewKeyDownHandler); Keyboard.AddKeyUpHandler(ListView, KeyUpHandler); base.OnAttached(); }
public MainWindow() { ApplicationManager.Current.InitializeSettings(); InitializeComponent(); DbHelper.verifyConnectionOpen(); this.Closing += closing; AppearanceManager.Current.AccentColor = Color.FromRgb(0x1b, 0xa1, 0xe2); /* * foreach (FontFamily f in System.Windows.Media.Fonts.SystemFontFamilies) * { * Console.Write(f.ToString()); * } */ FormattedText logoText = new FormattedText( MemberSignInSystem.ModernUI.Properties.Resources.LogoText, CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, new Typeface( new FontFamily("Magneto"), FontStyles.Normal, FontWeights.ExtraBold, FontStretches.Normal ), 50, System.Windows.Media.Brushes.Black ); // Font size (50) and brush color (black) are arbitrary. this.LogoData = logoText.BuildGeometry(new System.Windows.Point(0, 0)); // Declare keyboard listener Keyboard.AddPreviewKeyDownHandler(this, previewKeyEventHandler); keyListenerResetTimer.AutoReset = false; keyListenerResetTimer.Elapsed += delegate { if (listen) { ((RelayCommand)Application.Current.Resources["TextBoxDefaultStateCommand"]).Execute(null); (Application.Current.Resources["SubitCommand"] as RelayCommand).Execute(query); } g = false; ctrl = false; listen = false; query = ""; keyListenerResetTimer.Stop(); }; }
public void AddDialog(Window dlg) { if (dlg == null || _applicationDialogs.Contains(dlg)) { return; } _applicationDialogs.Add(dlg); Mouse.AddPreviewMouseMoveHandler(dlg, OnPreviewMouseMove); Keyboard.AddPreviewKeyDownHandler(dlg, OnPreviewKeyDown); dlg.Activated += OnWindowActivated; dlg.Deactivated += OnWindowDeactivated; }
void StartMoving() { var content = this.draggedItem.Content as FrameworkElement; if (content != null) { this.dragWindowSize = new Size(content.ActualWidth, content.ActualHeight); } else { this.dragWindowSize = new Size(500, 300); } this.draggedItem.Cursor = Cursors.SizeAll; this.dragShadow = new Window { AllowsTransparency = true, ShowInTaskbar = false, WindowStyle = WindowStyle.None, Width = dragWindowSize.Width, Height = dragWindowSize.Height, Background = new SolidColorBrush(Color.FromArgb(0x70, 0xbf, 0xdf, 0xff)), Topmost = true, ShowActivated = false }; var dragImage = new ActivatableTabControl() { Background = Brushes.Transparent, Opacity = 0.7 }; dragImage.Items.Add(new ActivatableTabItem { Header = draggedItem.Header }); this.dragShadow.Content = dragImage; this.dragShadow.Show(); var pos = this.draggedItem.PointToScreenIndependent(this.offset); this.dragShadow.Left = pos.X - offset.X; this.dragShadow.Top = pos.Y - offset.Y; this.preMoving = false; this.focusedElement = Keyboard.FocusedElement as DependencyObject; if (this.focusedElement != null) { Keyboard.AddPreviewKeyDownHandler(this.focusedElement, new KeyEventHandler(OnPreviewKeyDown)); Keyboard.AddPreviewKeyUpHandler(this.focusedElement, new KeyEventHandler(OnPreviewKeyUp)); } }
private void ControlLoaded([NotNull] object sender, [NotNull] RoutedEventArgs e) { Debug.ArgumentNotNull(sender, nameof(sender)); Debug.ArgumentNotNull(e, nameof(e)); Loaded -= ControlLoaded; if (Target == null) { Target = this.GetAncestor <IContextProvider>() as DependencyObject; } if (Target == null) { Target = this.GetAncestor <UserControl>(); } if (Target == null) { Target = this.GetAncestor <Window>(); } if (Target == null) { return; } if (UsePreviewEvent) { Keyboard.AddPreviewKeyDownHandler(Target, HandleKeyDown); } else { Keyboard.AddKeyDownHandler(Target, HandleKeyDown); } }