public static void Save(Window window, Type viewModelType)
        {
            var filename = Path.Combine(ApplicationData.Current.LocalFolder.FullName, viewModelType.FullName.GetHash() + "_Navigator");

            var dictionary = new KeyRawValueDictionary();

            dictionary.Add("Width", Mathc.Clamp(PersistentWindowProperties.GetWidth(window), window.MinWidth, window.MaxWidth));
            dictionary.Add("Height", Mathc.Clamp(PersistentWindowProperties.GetHeight(window), window.MinHeight, window.MaxHeight));
            dictionary.Add("Top", window.Top);
            dictionary.Add("Left", window.Left);
            dictionary.Add("WindowState", (int)window.WindowState);

            File.WriteAllBytes(filename, dictionary.Serialize());
        }
Esempio n. 2
0
        public static void Load(Window window, Type viewModelType)
        {
            PersistentWindowProperties.SetHeight(window, MathEx.Clamp(window.ActualHeight, window.MinHeight, window.MaxHeight));
            PersistentWindowProperties.SetWidth(window, MathEx.Clamp(window.ActualWidth, window.MinWidth, window.MaxWidth));

            var filename = Path.Combine(ApplicationData.Current.LocalFolder.FullName, viewModelType.FullName.GetHash() + "_Navigator");

            if (!File.Exists(filename))
            {
                return;
            }

            var dictionary = new KeyRawValueDictionary();

            dictionary.Deserialize(File.ReadAllBytes(filename));

            window.WindowStartupLocation = WindowStartupLocation.Manual;
            window.Left        = dictionary["Left"].ToDouble();
            window.Top         = dictionary["Top"].ToDouble();
            window.Height      = Math.Max(dictionary["Height"].ToDouble(), 1);
            window.Width       = Math.Max(dictionary["Width"].ToDouble(), 1);
            window.WindowState = (WindowState)dictionary["WindowState"].ToInteger();
        }