/// <summary>
 /// Recursively registers  all <see cref="ILogical"/>s in <paramref name="logicals"/> to the <paramref name="bindingContext"/>.
 /// </summary>
 /// <param name="logicals">A <see cref="Queue{T}"/> containing the root controls that will be recursively registered.</param>
 /// <param name="bindingContext">The <see cref="BindingContext"/> the <see cref="ScalableObject"/>s will be registered to.</param>
 public static void RegisterControls(Queue <IEnumerable <ILogical> > logicals, BindingContext bindingContext)
 {
     while (logicals.Count > 0)
     {
         IEnumerable <ILogical> children = logicals.Dequeue();
         foreach (ILogical child in children)
         {
             logicals.Enqueue(child.GetLogicalChildren());
             if (child is AvaloniaObject avaloniaObject)
             {
                 ScalableObject scalableObject = new ScalableObject(avaloniaObject);
                 bindingContext.Add(scalableObject);
             }
         }
     }
 }
        /// <summary>
        /// Creates a new <see cref="ScalingManager"/> and sets up all bindings of the <paramref name="window"/>.
        /// </summary>
        /// <param name="window">The <see cref="ScalableWindow"/> to be managed by this <see cref="ScalingManager"/>.</param>
        /// <param name="viewModel">The <see cref="IViewModel"/> implemented by the view model belonging to the <paramref name="window"/>.</param>
        public ScalingManager(ScalableWindow window, IViewModel viewModel)
        {
            this.viewModel     = viewModel;
            this.window        = window;
            ScalableMainWindow = new ScalableObject(window);
            BindingContext windowBindingContext = new BindingContext
            {
                ScalableMainWindow
            };

            Bindings.Add(window.GetType(), windowBindingContext);
            Queue <IEnumerable <ILogical> > logicals = new Queue <IEnumerable <ILogical> >();

            logicals.Enqueue(window.GetLogicalChildren());
            RegisterControls(logicals, window.GetType());
            MainWindowHeightScalable = ScalableMainWindow.Bindings.GetValueOrDefault(nameof(Layoutable.Height)) as Scalable <double>;
            MainWindowWidthScalable  = ScalableMainWindow.Bindings.GetValueOrDefault(nameof(Layoutable.Width)) as Scalable <double>;

            double optimalWidth  = window.Screens.Primary.WorkingArea.Width / 2;
            double optimalHeight = window.Screens.Primary.WorkingArea.Height / 2;

            double width  = optimalWidth;
            double height = optimalHeight;

            for (int i = 1; i < 4; i++)
            {
                if (height < MainWindowHeightScalable.DefaultValue || width < MainWindowWidthScalable.DefaultValue)
                {
                    width  = optimalWidth + (i * 0.125d);
                    height = optimalHeight + (i * 0.125d);
                }
            }
            double scalingFactor = Math.Min(width / MainWindowWidthScalable.DefaultValue, height / MainWindowHeightScalable.DefaultValue);

            SetScaling(scalingFactor);
            window.BeginResize     += Window_BeginResize;
            window.Resize          += Window_Resize;
            window.EndResize       += Window_EndResize;
            window.PropertyChanged += Window_PropertyChanged;
            window.PositionChanged += Window_PositionChanged;
        }