private void OnRendering(Object sender, EventArgs e)
        {
            _sbSelected.Clear();
            _isChanged = false;

            var element = _viewHost.View;

            //MeasureContext.ViewState = _viewHost;
            var size = new ValueRenderSize(_viewHost.RenderMargin.Width,
                                           _viewHost.RenderMargin.Height);

            var measured = MeasureContext.MeasureMainView(element, size,
                                                          _viewHost);
            var selectedVisual = SelectedVisuals?.FirstOrDefault();

            if (selectedVisual == null)
            {
                return;
            }

            _sbSelected.AppendLine(element.ToString());
            _sbSelected.AppendLine("Measured: " + measured);
            _sbSelected.AppendLine("Arranged: " + selectedVisual.Position);

            var nonDefaults = GetNonDefaultSetters(element).ToArray();

            foreach (var kvp in nonDefaults)
            {
                _sbSelected.AppendLine(kvp.ToString());
            }
            //_sbSelected.AppendLine(kvp.Key + ": " + kvp.Value);


            _rightRectangle = new Rectangle(_viewHost.AvailableSize.Width -
                                            _viewHost.RenderMargin.Right,
                                            0, _viewHost.RenderMargin.Width, _viewHost.AvailableSize.Height);
            //RenderContext.ViewState = _viewHost;
            RenderContext.FillRectangle(_rightRectangle, SolidColorBrush.DarkGray);

            if (selectedVisual.Element == null)
            {
                return;
            }


            RenderContext.DrawString(_sbSelected.ToString(), _font,
                                     _rightRectangle, SolidColorBrush.White);
        }
        public BitmapRenderer(IViewHost <Bitmap> viewHost,
                              GdiMeasureContext measureContext,
                              GdiRenderContext renderContext,
                              Color backgroundColor)
        {
            _eventLock = new Object();

            _lock       = new Object();
            _viewHost   = viewHost;
            _visualHost = viewHost;

            _visualHost.AvailableSizeChanged += OnHostSizeChanged;

            _measureContext = measureContext;
            _renderContext  = renderContext;
            _layoutQueue    = measureContext.LayoutQueue;
            _gdiDevice      = new GdiDevice(backgroundColor,
                                            _viewHost.AvailableSize);

            _renderRect = new Rectangle(0, 0, 1, 1);

            _hostRect = new ValueRectangle(0, 0, viewHost.AvailableSize);
        }