Exemple #1
0
        public bool Equals(BitmapLoadProperties other)
        {
            if (other is null)
            {
                return(false);
            }

            if (DpiScale?.Equals(other.DpiScale) == false)
            {
                return(false);
            }

            if (MaxDecodePixelWidth != other.MaxDecodePixelWidth)
            {
                return(false);
            }

            if (MaxDecodePixelHeight != other.MaxDecodePixelHeight)
            {
                return(false);
            }

            if (!string.Equals(Source, other.Source, StringComparison.Ordinal))
            {
                return(false);
            }

            return(true);
        }
Exemple #2
0
        private void SetDrawingFactor(DpiScale dpi = default)
        {
            if (dpi.Equals(default(DpiScale)))
            {
                dpi = VisualTreeHelper.GetDpi(this);
            }

            _drawingFactor = dpi.DpiScaleX;
        }
Exemple #3
0
 /// <summary>
 /// Determines whether a specified DPI indicates identity scaling.
 /// </summary>
 /// <param name="dpi">DPI scale information</param>
 /// <returns>True if identity scaling. False otherwise.</returns>
 public static bool IsIdentity(this DpiScale dpi) => dpi.Equals(Identity);
Exemple #4
0
        /// <summary>
        /// Manages layout of Window components.
        /// </summary>
        protected void ManageLayout(DpiScale dpi = default)
        {
            if (!dpi.Equals(default(DpiScale)))
            {
                WindowDpi = dpi;
            }
            else if (WindowDpi.Equals(default(DpiScale)))
            {
                WindowDpi = VisualTreeHelper.GetDpi(this);
            }

            var factorFromDefaultX = WindowDpi.DpiScaleX;
            var factorFromDefaultY = WindowDpi.DpiScaleY;
            var factorFromSystemX  = WindowDpi.DpiScaleX / SystemDpi.DpiScaleX;
            var factorFromSystemY  = WindowDpi.DpiScaleY / SystemDpi.DpiScaleY;

            var captionHeight = 0D;

            // Manage chrome border.
            if (this.WindowState == WindowState.Maximized)
            {
                if (ChromeOutmostBorder != null)
                {
                    ChromeOutmostBorder.BorderThickness = new Thickness(
                        SystemParameters.WindowResizeBorderThickness.Left + SystemParameters.WindowNonClientFrameThickness.Left,
                        SystemParameters.WindowResizeBorderThickness.Left + SystemParameters.WindowNonClientFrameThickness.Left,                         // Use Left values.
                        SystemParameters.WindowResizeBorderThickness.Right + SystemParameters.WindowNonClientFrameThickness.Right,
                        SystemParameters.WindowResizeBorderThickness.Bottom + SystemParameters.WindowNonClientFrameThickness.Bottom);

                    captionHeight += ChromeOutmostBorder.BorderThickness.Top;
                }

                if (ChromeBorder != null)
                {
                    ChromeBorder.BorderThickness = new Thickness(0D);
                }
            }
            else
            {
                if (ChromeOutmostBorder != null)
                {
                    ChromeOutmostBorder.BorderThickness = new Thickness(0D);

                    captionHeight += ChromeBorderThickness.Top;
                }

                if (ChromeBorder != null)
                {
                    ChromeBorder.BorderThickness = new Thickness(
                        ChromeBorderThickness.Left / factorFromDefaultX,
                        ChromeBorderThickness.Top / factorFromDefaultY,
                        ChromeBorderThickness.Right / factorFromDefaultX,
                        ChromeBorderThickness.Bottom / factorFromDefaultY);
                }
            }

            // Manage title bar and content border.
            if ((this.WindowState == WindowState.Maximized) && !KeepsTitleContentMargin)
            {
                if (TitleBarGrid != null)
                {
                    TitleBarGrid.Height = TitleBarMaximizedHeight.ToRounded(factorFromDefaultY);
                    TitleBarPaddingLeft = 0D;
                }

                if (WindowContentBorder != null)
                {
                    WindowContentBorder.Margin          = new Thickness(0D);
                    WindowContentBorder.BorderThickness = new Thickness(
                        0D,
                        ContentBorderThickness.Top / factorFromDefaultY,
                        0D,
                        0D);
                }
            }
            else
            {
                if (TitleBarGrid != null)
                {
                    TitleBarGrid.Height = TitleBarNormalHeight.ToRounded(factorFromDefaultY);
                    TitleBarPaddingLeft = Math.Ceiling(Math.Max(TitleBarGrid.Height - IconSize.Height, 0D) / 2).ToRounded(factorFromDefaultX);
                }

                if (WindowContentBorder != null)
                {
                    WindowContentBorder.Margin = new Thickness(
                        ContentMargin.Left.ToRounded(factorFromDefaultX),
                        ContentMargin.Top.ToRounded(factorFromDefaultY),
                        ContentMargin.Right.ToRounded(factorFromDefaultX),
                        ContentMargin.Bottom.ToRounded(factorFromDefaultY));
                    WindowContentBorder.BorderThickness = new Thickness(
                        ContentBorderThickness.Left / factorFromDefaultX,
                        ContentBorderThickness.Top / factorFromDefaultY,
                        ContentBorderThickness.Right / factorFromDefaultX,
                        ContentBorderThickness.Bottom / factorFromDefaultY);
                }
            }

            // Set caption height for WindowChrome.CaptionHeight.
            if (TitleBarGrid != null)
            {
                captionHeight += Math.Round((TitleBarGrid.Height + ContentBorderThickness.Top) * factorFromSystemY);
            }

            var windowChrome = WindowChrome.GetWindowChrome(this);

            if (windowChrome != null)
            {
                windowChrome.CaptionHeight = Math.Max(captionHeight - SystemParameters.WindowResizeBorderThickness.Top, 0D);
            }
        }