Esempio n. 1
0
        /// <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 static void Register(ScalableWindow window, IViewModel viewModel)
        {
            Type type = window.GetType();

            if (!scalingManagers.ContainsKey(type))
            {
                ScalingManager scalingManager = new ScalingManager(window, viewModel);
                scalingManagers.Add(type, scalingManager);
            }
        }
        /// <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;
        }