コード例 #1
0
        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();
        }
コード例 #2
0
        public Size Measure(string text, double fontSize, Typeface typeface, double maxWidth)
        {
            if (!text.IsNullOrEmpty() && text.EndsWith(Environment.NewLine))
            {
                text += " ";
            }

            wpf::System.Windows.Media.FormattedText formattedText = new wpf::System.Windows.Media.FormattedText(
                text.DefaultIfNullOrEmpty("A"),
                System.Globalization.CultureInfo.CurrentCulture,
                wpf::System.Windows.FlowDirection.LeftToRight,
                converter.Convert(typeface),
                fontSize,
                wpf::System.Windows.Media.Brushes.Black);

            formattedText.Trimming     = wpf::System.Windows.TextTrimming.None;
            formattedText.MaxTextWidth = Double.IsInfinity(maxWidth) ? 0 : maxWidth;

            return(new Size(text.IsNullOrEmpty() ? 0 : Math.Ceiling(formattedText.WidthIncludingTrailingWhitespace + 4), Math.Ceiling(formattedText.Height)));
        }
コード例 #3
0
 private void OnForegroundChanged(object sender, EventArgs e)
 {
     textBlock.Foreground = converter.Convert(Foreground);
 }
コード例 #4
0
 private void OnBackgroundChanged(object sender, EventArgs e)
 {
     container.Background = converter.Convert(Background);
 }