//hook into the window loaded event to apply things that should be done to all child windows of the mainWindow
 private void OnWindowLoaded(object sender, RoutedEventArgs e)
 {
     //get the original width and height
     OriginalHeight = Height;
     OriginalWidth  = Width;
     //deal with the translations
     if (LocalizeWindow)
     {
         Translations.LocalizeWindow(this, ApplyToolTips);
     }
     //apply UI color changes
     if (ApplyColorSettings)
     {
         UISettings.ApplyCustomStyles(this);
         UISettings.ApplyUIColorSettings(this);
     }
     //deal with scaling
     if (ApplyScaling)
     {
         //get current scaling of window (like from display settings)
         double currentScale = PresentationSource.FromVisual(this).CompositionTarget.TransformToDevice.M11;
         //if current scale is not target(modpackSetting), then update
         if (ModpackSettings.DisplayScale != currentScale)
         {
             Utils.ApplyApplicationScale(this, ModpackSettings.DisplayScale);
         }
     }
 }
示例#2
0
        /// <summary>
        /// Performs custom window loading functions that should be done to all windows of this class
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <remarks>This function saves the original size that the window was designed for (scaling), applies localizations, applies color settings,
        /// applies custom font, and applies scaling. Each application action is controlled by a boolean.</remarks>
        protected virtual void OnWindowLoaded(object sender, RoutedEventArgs e)
        {
            //get the original width and height
            OriginalHeight = Height;
            OriginalWidth  = Width;

            //subscribe to the event of the escape key pressed closing the window
            if (EscapeKeyClosesWindow)
            {
                KeyUp += OnKeyUp;
            }

            //deal with the translations
            if (LocalizeWindow)
            {
                Translations.LocalizeWindow(this, ApplyToolTips);
            }

            //apply UI color changes
            if (ApplyColorSettings)
            {
                UISettings.ApplyCustomStyles(this);
                UISettings.ApplyUIColorSettings(this);
            }

            //apply font changes
            if (ApplyCustomFont && ModpackSettings.EnableCustomFont)
            {
                ApplyFontToWindow();
            }

            //apply scaling
            if (ApplyScaling)
            {
                //get current scaling of window (like from display settings)
                double currentScale = PresentationSource.FromVisual(this).CompositionTarget.TransformToDevice.M11;
                //if current scale is not target(modpackSetting), then update
                if (ModpackSettings.DisplayScale != currentScale)
                {
                    ApplyApplicationScale(ModpackSettings.DisplayScale);
                }
            }

            Loaded -= OnWindowLoaded;
        }