/// <summary>
        /// Update all methods required for this instance.
        /// </summary>
        /// <param name="gameTime">The current game time</param>
        protected override void Update(TimeSpan gameTime)
        {
            this.UpdateViewSettings();

            this.totalTime += gameTime;

            if (this.renderer != null)
            {
                this.UpdateInputs();

                try
                {
                    this.view.Update(this.totalTime.TotalSeconds);
                }
                catch (Exception e)
                {
                    // This usually happens when the view datacontext references undefined items or with some Noesis limitations
                    NoesisErrorConsole.PrintPanelError(this.Owner.Name, e);
                }
            }
        }
        private void ChangeStyle(string style)
        {
            try
            {
                if (!this.noesisInitialized)
                {
                    this.noesisInitialized = true;

                    Noesis.GUI.Init();

                    Noesis.GUI.SetXamlProvider(this.xamlProvider);
                    Noesis.GUI.SetTextureProvider(this.textureProvider);
                    Noesis.GUI.SetFontProvider(this.fontProvider);
                }

                object theme = null;

                if (!string.IsNullOrEmpty(style))
                {
                    theme = Noesis.GUI.LoadXaml(style) ?? throw new Exception($"Unable to load style XAML {style}");
                    theme = theme as ResourceDictionary ?? throw new Exception($"{style} is not a ResourceDictionary");
                }
                else
                {
                    this.style = null;
                }

                Noesis.GUI.SetApplicationResources((ResourceDictionary)theme);

                this.CurrentStyle = style;

                this.StyleValid = true;
            }
            catch (Exception e)
            {
                NoesisErrorConsole.PrintServiceError(e);
            }
        }
        /// <summary>
        /// Create the panel.
        /// </summary>
        private void CreatePanel()
        {
            if (!this.noesisService.StyleValid)
            {
                return;
            }

            this.viewSettingsDirty = false;

            this.totalTime = TimeSpan.Zero;

            try
            {
                if (!string.IsNullOrEmpty(this.Xaml))
                {
                    object root = Noesis.GUI.LoadXaml(this.Xaml);

                    if (root == null)
                    {
                        throw new Exception($"Unable to load XAML {this.Xaml}");
                    }

                    if (!(root is FrameworkElement))
                    {
                        throw new Exception($"{this.Xaml} is not a FrameworkElement");
                    }

                    this.view = Noesis.GUI.CreateView((FrameworkElement)root);

                    if (!this.IsRenderToTexture)
                    {
                        var vsm = this.Owner.Scene.VirtualScreenManager.VirtualScreenRectangle;

                        this.width  = (int)vsm.Width;
                        this.height = (int)vsm.Height;
                    }

                    if (this.width <= 0)
                    {
                        throw new Exception("Panel width must be positive");
                    }

                    if (this.height <= 0)
                    {
                        throw new Exception("Panel height must be positive");
                    }

                    this.view.SetSize(this.width, this.height);
                    this.view.SetIsPPAAEnabled(this.antiAliasingMode == View.AntialiasingMode.PPAA);
                    this.view.SetTessellationQuality(this.tessellationQuality);

                    // In OpenGL platforms, enable FlipY when the component is rendering to texture
                    View.RenderFlags renderFlags = this.renderFlags;
                    bool             doFlip      = (WaveServices.Platform.AdapterType != AdapterType.DirectX && this.IsRenderToTexture) ^ this.flipY;
                    renderFlags |= doFlip ? (View.RenderFlags)View.HiddenRenderFlags.FlipY : 0;
                    this.view.SetFlags(renderFlags);

                    this.renderer = this.view.Renderer;

                    this.NoesisBegin(false);
                    this.renderer.Init(this.noesisService.RenderDevice);
                    this.NoesisEnd();

                    this.view.Update(0);

                    if (!this.IsRenderToTexture)
                    {
                        this.camera.OnPreRender += this.Noesis_OnCameraPreRender;
                        this.EnablePostProcess   = this.enablePostProcess;
                    }
                    else
                    {
                        this.RenderManager.OnPreRender += this.Noesis_RenderToTexture;
                        this.transform      = this.Owner.FindComponent <Transform3D>(false);
                        this.screenViewport = new Viewport(0, 0, this.width, this.height);
                        this.renderTarget   = this.graphicsDevice.RenderTargets.CreateRenderTarget(this.width, this.height);

                        // Try to set the texture to the material.
                        this.SetPanelMaterialTexture(this.Texture);
                    }

                    this.OnViewCreated?.Invoke(this, this.view);
                }
            }
            catch (Exception e)
            {
                // This usually happens when loading a XAML with undefined resources or with an incorrect root type
                NoesisErrorConsole.PrintPanelError(this.Owner.Name, e);

                // Set default texture
                this.SetPanelMaterialTexture(StaticResources.DefaultTexture);
            }
        }
 /// <summary>
 /// Print a Noesis error caused by the NoesisService
 /// </summary>
 /// <param name="error">The error message.</param>
 internal static void PrintServiceError(Exception error)
 {
     NoesisErrorConsole.ConsoleWrite($"NoesisService error: {NoesisErrorConsole.GetMessageFromException(error)}");
 }
 /// <summary>
 /// Print a Noesis error caused by a NoesisPanel
 /// </summary>
 /// <param name="componentName">The name of the component which caused the error.</param>
 /// <param name="error">The error message.</param>
 internal static void PrintPanelError(string componentName, Exception error)
 {
     NoesisErrorConsole.ConsoleWrite($"NoesisPanel error ({componentName}): {NoesisErrorConsole.GetMessageFromException(error)}");
 }