Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the WindowsFormsHost class.
        /// </summary>
        public WindowsFormsHost()
            : base()
        {
            this._hostContainerInternal = new WinFormsAdapter(this);

            _propertyMap = new WindowsFormsHostPropertyMap(this);
        }
 /// <summary>
 ///     Translator for individual property
 /// </summary>
 private void ForegroundPropertyTranslator(object host, string propertyName, object value)
 {
     SWM.Brush brush = value as SWM.Brush;
     if (brush != null)
     {
         bool     defined;
         SD.Color wfColor = WindowsFormsHostPropertyMap.TranslateSolidOrGradientBrush(brush, out defined);
         if (defined)
         {
             WinFormsAdapter adapter = GetAdapter(host);
             if (adapter != null)
             {
                 adapter.ForeColor = wfColor;
             }
         }
     }
 }
Exemplo n.º 3
0
        internal static SD.Bitmap GetBitmapForTransparentWindowsFormsHost(WindowsFormsHost host)
        {
            WinFormsAdapter adapter = WindowsFormsHostPropertyMap.GetAdapter(host);

            if (adapter == null)
            {
                return(null);
            }

            //We need to find our highest-level ancestor that's a FrameworkElement:
            //if it's not a FrameworkElement, we don't know how big it is, and can't
            //properly deal with it.
            FrameworkElement frameworkElementAncestor = GetFrameworkElementAncestor(host);

            if (frameworkElementAncestor != null)
            {
                RenderTargetBitmap bmp = GetBitmapForFrameworkElement(frameworkElementAncestor);

                Point hostPoint   = new Point(0, 0);
                Point parentPoint = new Point(0, 0);
                if (HostUtils.IsRotated(host))
                {
                    //Image is upside down.  Need the lower right corner of host and the
                    //lower right corner of the parent.
                    hostPoint = HostUtils.TransformToParentPoint(host, frameworkElementAncestor,
                                                                 new Point(host.ActualWidth, host.ActualHeight));

                    parentPoint = HostUtils.TransformToParentPoint(frameworkElementAncestor, frameworkElementAncestor,
                                                                   new Point(frameworkElementAncestor.ActualWidth, frameworkElementAncestor.ActualHeight));
                }
                else
                {
                    //Need upper left corner of host and the upper left corner of the parent.
                    hostPoint = HostUtils.TransformToParentPoint(host, frameworkElementAncestor,
                                                                 new Point(0, 0));

                    parentPoint = HostUtils.TransformToParentPoint(frameworkElementAncestor, frameworkElementAncestor,
                                                                   new Point(0, 0));
                }
                hostPoint.Offset(-parentPoint.X, -parentPoint.Y);
                return(GetBitmapFromRenderTargetBitmap(adapter, bmp, hostPoint));
            }
            return(null);
        }
Exemplo n.º 4
0
        internal static SD.Bitmap GetBitmapForOpaqueWindowsFormsHost(WindowsFormsHost host, Brush brush)
        {
            WinFormsAdapter adapter = WindowsFormsHostPropertyMap.GetAdapter(host);

            if (adapter == null)
            {
                return(null);
            }

            DrawingVisual  drawingVisual  = new DrawingVisual();
            DrawingContext drawingContext = drawingVisual.RenderOpen();

            drawingContext.DrawRectangle(brush, null, new Rect(0, 0, adapter.Width, adapter.Height));
            drawingContext.Close();

            RenderTargetBitmap bmp = GetRenderTargetBitmapForVisual(adapter.Width, adapter.Height, drawingVisual);

            return(GetBitmapFromRenderTargetBitmap(adapter, bmp, new Point(0, 0)));
        }
        private void BackgroundPropertyTranslator(object host, string propertyName, object value)
        {
            SWM.Brush brush = value as SWM.Brush;

            if (value == null)
            {
                //If they passed null (not to be confused with "passed us a non-null non-Brush"),
                //we should look up our parent chain.
                DependencyObject parent = host as WindowsFormsHost;
                do
                {
                    brush  = (Brush)parent.GetValue(SWC.Control.BackgroundProperty);
                    parent = VisualTreeHelper.GetParent(parent);
                } while (parent != null && brush == null);
            }

            WinFormsAdapter adapter = GetAdapter(host);

            if (adapter != null && brush != null)
            {
                WindowsFormsHost windowsFormsHost = host as WindowsFormsHost;
                if (windowsFormsHost != null)
                {
                    SWF.Control child = windowsFormsHost.Child;

                    if (HostUtils.BrushIsSolidOpaque(brush))
                    {
                        bool     ignore;
                        SD.Color wfColor = WindowsFormsHostPropertyMap.TranslateSolidOrGradientBrush(brush, out ignore);
                        adapter.BackColor = wfColor;
                    }
                    else
                    {
                        SD.Bitmap backgroundImage = HostUtils.GetBitmapForWindowsFormsHost(windowsFormsHost, brush);
                        HostUtils.SetBackgroundImage(adapter, child, backgroundImage);
                    }
                }
            }
        }