/// <summary>
        /// Attaches the renderer to the given SwapChainBackgroundPanel.
        /// </summary>
        /// <param name="targetPanel">The target panel to attach to.</param>
        private void AttachInternal(SwapChainPanelWrapper targetPanel)
        {
            if (m_targetPanel != null)
            {
                throw new InvalidOperationException("Unable to attach to new SwapChainBackgroundPanel: Renderer is already attached to another one!");
            }

            m_lastRefreshTargetSize = new Size(0.0, 0.0);
            m_targetPanel           = targetPanel;

            // Attach to SizeChanged event (refresh view resources only after a specific time)
            m_observerSizeChanged = Observable.FromEventPattern <SizeChangedEventArgs>(m_targetPanel, "SizeChanged")
                                    .Throttle(TimeSpan.FromSeconds(0.5))
                                    .ObserveOn(SynchronizationContext.Current)
                                    .Subscribe((eArgs) => OnTargetPanelThrottled_SizeChanged(eArgs.Sender, eArgs.EventArgs));

            m_targetPanel.SizeChanged             += OnTargetPanel_SizeChanged;
            m_targetPanel.Loaded                  += OnTargetPanel_Loaded;
            m_targetPanel.Unloaded                += OnTargetPanel_Unloaded;
            m_targetPanel.CompositionScaleChanged += OnTargetPanel_CompositionScaleChanged;

            UpdateRenderLoopViewSize();

            // Define unloading behavior
            if (VisualTreeHelper.GetParent(m_targetPanel.Panel) != null)
            {
                m_renderLoop.RegisterRenderLoop();
            }
        }
        /// <summary>
        /// Detaches the renderer from the current target panel.
        /// </summary>
        public void Detach()
        {
            try
            {
                if (m_targetPanel == null)
                {
                    return;
                }

                // Clear view resources
                m_renderLoop.UnloadViewResources();
                m_renderLoop.DeregisterRenderLoop();

                // Clear event registrations
                m_targetPanel.SizeChanged             -= OnTargetPanel_SizeChanged;
                m_targetPanel.Loaded                  -= OnTargetPanel_Loaded;
                m_targetPanel.Unloaded                -= OnTargetPanel_Unloaded;
                m_targetPanel.CompositionScaleChanged -= OnTargetPanel_CompositionScaleChanged;

                //Clear created references
                m_observerSizeChanged.Dispose();
                m_observerSizeChanged = null;
                m_targetPanel.Dispose();
                m_targetPanel = null;
            }
            catch (Exception ex)
            {
                CommonTools.RaiseUnhandledException(
                    this.GetType(), this, ex,
                    "Detaching the FrozenSyBackgroundPanelPainter");
            }
        }