Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes372downloads
1// Copyright (c) Microsoft Corporation.2// Licensed under the MIT License.3 4using System.Windows;5 6// Specifies the location in which theme dictionaries are stored for types in an assembly.7[assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)]8 9namespace Microsoft.Management.UI10{11    /// <summary>12    /// Utilities in common in this assembly.13    /// </summary>14    internal static class CommonHelper15    {16        /// <summary>17        /// Restore the values from the settings to the actual window position, size and state.18        /// </summary>19        /// <param name="target">The window we are setting position and size of.</param>20        /// <param name="userSettingTop">The value for top from the user settings.</param>21        /// <param name="userSettingLeft">The value for left from the user settings.</param>22        /// <param name="userSettingWidth">The value for width from the user settings.</param>23        /// <param name="userSettingHeight">The value for height from the user settings.</param>24        /// <param name="defaultWidth">The with used if <paramref name="userSettingWidth"/> is not valid.</param>25        /// <param name="defaultHeight">The height used if <paramref name="userSettingHeight"/> is not valid.</param>26        /// <param name="userSettingMaximized">True if the window is maximized in the user setting.</param>27        internal static void SetStartingPositionAndSize(Window target, double userSettingTop, double userSettingLeft, double userSettingWidth, double userSettingHeight, double defaultWidth, double defaultHeight, bool userSettingMaximized)28        {29            bool leftInvalid = userSettingLeft < System.Windows.SystemParameters.VirtualScreenLeft ||30                            userSettingWidth > System.Windows.SystemParameters.VirtualScreenLeft +31                            System.Windows.SystemParameters.VirtualScreenWidth;32 33            bool topInvalid = userSettingTop < System.Windows.SystemParameters.VirtualScreenTop ||34                userSettingTop > System.Windows.SystemParameters.VirtualScreenTop +35                            System.Windows.SystemParameters.VirtualScreenHeight;36 37            bool widthInvalid = userSettingWidth < 0 ||38                userSettingWidth > System.Windows.SystemParameters.VirtualScreenWidth;39 40            bool heightInvalid = userSettingHeight < 0 ||41                userSettingHeight > System.Windows.SystemParameters.VirtualScreenHeight;42 43            if (leftInvalid || topInvalid)44            {45                target.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;46            }47            else48            {49                target.Left = userSettingLeft;50                target.Top = userSettingTop;51            }52 53            // If any saved coordinate is invalid, we set the window to the default position54            if (widthInvalid || heightInvalid)55            {56                target.Width = defaultWidth;57                target.Height = defaultHeight;58            }59            else60            {61                target.Width = userSettingWidth;62                target.Height = userSettingHeight;63            }64 65            if (userSettingMaximized)66            {67                target.WindowState = WindowState.Maximized;68            }69        }70    }71}72