} // proc LoadInternAsync /// <summary>Control is created.</summary> protected virtual void OnControlCreated() { CallMemberDirect(nameof(OnControlCreated), Array.Empty <object>(), rawGet: true, ignoreNilFunction: true); Mouse.AddPreviewMouseDownHandler(Control, Control_MouseDownHandler); Mouse.AddPreviewMouseDownOutsideCapturedElementHandler(Control, Control_MouseDownHandler); Keyboard.AddPreviewGotKeyboardFocusHandler(Control, Control_GotKeyboardFocusHandler); Keyboard.AddPreviewLostKeyboardFocusHandler(Control, Control_LostKeyboardFocusHandler); Keyboard.AddPreviewKeyUpHandler(Control, Control_KeyUpHandler); } // proc OnControlCreated
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)); } }
public PreviewViewVM(IApplicationCommands applicationCommands) { _applicationCommands = applicationCommands; using (Graphics g = Graphics.FromHwnd(IntPtr.Zero)) { _dpiX = g.DpiX; _dpiY = g.DpiY; } foreach (Window window in Application.Current.Windows) { Mouse.AddMouseUpHandler(window, new MouseButtonEventHandler(MouseUpEvent)); Keyboard.AddPreviewKeyUpHandler(window, new KeyEventHandler(KeyUpEvent)); } _timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(1.5) }; _timer.Tick += Timer_Tick; }