private void RestoreWindowPosition(WindowPlacementInfo wp) { _ = wp ?? throw new ArgumentNullException(nameof(wp)); // Validation routine will cope with Null being passed and if it finds an error, it returns null. wp = ValidateScreenPosition(wp); if (wp != null) { Log.TraceFormat( "Window position being restored to ({0},{1})-({2},{3}) {4}", wp.Top, wp.Left, wp.Top + wp.Height, wp.Left + wp.Width, wp.WindowState); Top = wp.Top; Left = wp.Left; Width = wp.Width; Height = wp.Height; // TODO: would it make sense to start up minimized if that was how it was terminated? WindowState = wp.WindowState; } }
private static WindowPlacementInfo ValidateScreenPosition(WindowPlacementInfo wp) { if (wp != null) { var virtualScreen = new Rect( SystemParameters.VirtualScreenLeft, SystemParameters.VirtualScreenTop, SystemParameters.VirtualScreenWidth, SystemParameters.VirtualScreenHeight); var window = new Rect(wp.Left, wp.Top, wp.Width, wp.Height); return(virtualScreen.IntersectsWith(window) ? wp : null); } return(null); }
private void OnClosed(object sender, CancelEventArgs e) { var windowInfo = new WindowPlacementInfo { Height = (int)Height, Top = (int)Top, Left = (int)Left, Width = (int)Width, WindowState = WindowState, }; var filename = Path.ChangeExtension(persistingFilename, ".json"); PersistingSettings.Save(filename, windowInfo, Preferences); var recentFileInfo = new RecentFileInfo { RecentFilePaths = RecentFiles.ToList() }; JsonHelper.SerializeToFile(recentFileInfo, Path.ChangeExtension(persistingRecentFileName, ".json")); }
internal static void Save(string fileName, WindowPlacementInfo placementInfo, IUserPreferences userPreferences) { if (string.IsNullOrWhiteSpace(fileName)) { throw new ArgumentException("Value cannot be null or whitespace.", nameof(fileName)); } var wrapper = new PersistingSettings { WindowPlacementInfo = placementInfo, UserPreferences = userPreferences, }; try { JsonHelper.SerializeToFile(wrapper, fileName); } catch (Exception e) { Trace.TraceError($"Unable to write persistence file: {e.Message}"); } }
private static WindowPlacementInfo ValidateScreenPosition(WindowPlacementInfo wp) { if (wp == null) { return(null); } try { var virtualScreen = new Rect( SystemParameters.VirtualScreenLeft, SystemParameters.VirtualScreenTop, SystemParameters.VirtualScreenWidth, SystemParameters.VirtualScreenHeight); var window = new Rect(wp.Left, wp.Top, wp.Width, wp.Height); return(virtualScreen.IntersectsWith(window) ? wp : null); } catch (Exception e) { log.Error("Unable to calculate rectangle or perform intersection with window", e); } return(null); }
private void OnClosed(object sender, CancelEventArgs e) { var windowInfo = new WindowPlacementInfo { Height = (int)Height, Top = (int)Top, Left = (int)Left, Width = (int)Width, WindowState = WindowState }; var filename = Path.ChangeExtension(persistingFilename, ".json"); JsonHelper.SerializeToFile(windowInfo, filename); var recentFileInfo = new RecentFileInfo { RecentFilePaths = RecentFiles.ToList(), }; JsonHelper.SerializeToFile(recentFileInfo, Path.ChangeExtension(persistingRecentFileName, ".json")); }
private static WindowPlacementInfo ValidateScreenPosition(WindowPlacementInfo wp) { if (wp == null) { return null; } try { var virtualScreen = new Rect( SystemParameters.VirtualScreenLeft, SystemParameters.VirtualScreenTop, SystemParameters.VirtualScreenWidth, SystemParameters.VirtualScreenHeight); var window = new Rect(wp.Left, wp.Top, wp.Width, wp.Height); return virtualScreen.IntersectsWith(window) ? wp : null; } catch (Exception e) { log.Error("Unable to calculate rectangle or perform intersection with window", e); } return null; }
private static WindowPlacementInfo ValidateScreenPosition(WindowPlacementInfo wp) { if (wp != null) { var virtualScreen = new Rect( SystemParameters.VirtualScreenLeft, SystemParameters.VirtualScreenTop, SystemParameters.VirtualScreenWidth, SystemParameters.VirtualScreenHeight); var window = new Rect(wp.Left, wp.Top, wp.Width, wp.Height); return virtualScreen.IntersectsWith(window) ? wp : null; } return null; }