public WpfPresentationSource(UIElement rootElement, IWpfValueConverter converter) { this.RootElement = rootElement; this.converter = converter; RootElement.IsRootElement = true; MouseDevice = new MouseDevice(this); KeyboardDevice = new KeyboardDevice(this); container = new wpf::System.Windows.Controls.Canvas { Background = wpf::System.Windows.Media.Brushes.Transparent }; container.PreviewMouseMove += OnContainerMouseMove; container.PreviewMouseDown += OnContainerMouseDown; container.PreviewMouseUp += OnContainerMouseUp; container.PreviewMouseWheel += (sender, e) => e.Handled = MouseDevice.ProcessRawEvent(new RawMouseWheelEventArgs(e.Delta, converter.ConvertBack(e.GetPosition(container)), GetTimestamp())); MouseDevice.CursorChanged += (sender, e) => container.Cursor = converter.Convert(MouseDevice.Cursor); container.Cursor = converter.Convert(MouseDevice.Cursor); window = new wpf::System.Windows.Window { UseLayoutRounding = true, Content = container }; window.Activated += (sender, e) => MouseDevice.Activate(); window.Deactivated += (sender, e) => MouseDevice.Deactivate(); window.SizeChanged += (sender, e) => SetRootElementSize(); window.PreviewKeyDown += (sender, e) => e.Handled = KeyboardDevice.ProcessRawEvent(new RawKeyboardEventArgs(converter.ConvertBack(e.Key), converter.ConvertBack(e.KeyStates), e.IsRepeat, GetTimestamp())); window.PreviewKeyUp += (sender, e) => e.Handled = KeyboardDevice.ProcessRawEvent(new RawKeyboardEventArgs(converter.ConvertBack(e.Key), converter.ConvertBack(e.KeyStates), e.IsRepeat, GetTimestamp())); window.Show(); container.Children.Add(((IWpfRenderElement)rootElement.GetRenderElement(WpfRenderElementFactory.Default)).WpfElement); SetRootElementSize(); MouseDevice.Activate(); KeyboardDevice.Activate(); }
private void OnContainerMouseDown(object sender, wpf::System.Windows.Input.MouseButtonEventArgs e) { e.MouseDevice.Capture(container); e.Handled = MouseDevice.ProcessRawEvent(new RawMouseButtonEventArgs(converter.ConvertBack(e.ChangedButton), converter.ConvertBack(e.ButtonState), converter.ConvertBack(e.GetPosition(container)), GetTimestamp())); if (!e.Handled) { e.MouseDevice.Capture(null); } }