示例#1
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)
            {
                UiUtils.ApplyFontToWindow(this, UiUtils.CustomFontFamily);
            }

            //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)
                {
                    UiUtils.ApplyApplicationScale(this, ModpackSettings.DisplayScale);
                }
            }

            Loaded -= OnWindowLoaded;
        }