public static void Load(System.Windows.Window wnd, Action <Dictionary <string, WindowStateData>, string> callback = null) { var wndPos = GetWindowPositionData(); if (wndPos == null) { return; } var typeName = wnd.GetType().ToString(); if (!wndPos.ContainsKey(typeName)) { return; } var pos = wndPos[typeName]; wnd.Left = pos.Left; wnd.Top = pos.Top; wnd.Width = pos.Width; wnd.Height = pos.Height; wnd.WindowState = pos.WndState; if (callback != null) { callback(wndPos, typeName); } }
private static void SetScreen(System.Windows.Window win) //设置屏幕位置 { var attr = win.GetType().GetCustomAttributes(typeof(MultipScreenAttribute), false).FirstOrDefault(o => o is MultipScreenAttribute); // int index = 1; int index = CallSystem.Class.Config.ScreenIndex; bool ingoreOperation = false; WindowStartupLocationInScreen inScreen = WindowStartupLocationInScreen.CenterScreen; if (attr != null) { var temp = (attr as MultipScreenAttribute); index = temp.Index; inScreen = temp.InScreen; ingoreOperation = temp.IngoreMinorScreenError; } Screen screen = PrimaryScreen; if (index == 1 && FirstMinorScreen != null) { screen = FirstMinorScreen; } else if (index > 1 && index < MinorScreens.Count()) { screen = MinorScreens.ElementAt(index); } else if (index > 0 && index >= MinorScreens.Count() && ingoreOperation) { return; } switch (inScreen) { case WindowStartupLocationInScreen.CenterScreen: SetWindowInScreenCenter(win, screen); break; case WindowStartupLocationInScreen.Manual: SetWindowInScreenManual(win, screen); break; } }
public static void Save(System.Windows.Window wnd, Action <Dictionary <string, WindowStateData>, string> callback = null) { var wndPos = GetWindowPositionData(); var typeName = wnd.GetType().ToString(); var data = new List <WindowStateData>(); if (wndPos == null) { wndPos = new Dictionary <string, WindowStateData>(); wndPos[typeName] = new WindowStateData(); } else { if (!wndPos.ContainsKey(typeName)) { wndPos[typeName] = new WindowStateData(); } } using (StreamWriter sw = File.CreateText(AppStateFilePath)) { wndPos[typeName].WndName = typeName; wndPos[typeName].Top = wnd.Top; wndPos[typeName].Left = wnd.Left; wndPos[typeName].Width = wnd.Width; wndPos[typeName].Height = wnd.Height; wndPos[typeName].WndState = wnd.WindowState; if (callback != null) { callback(wndPos, typeName); } var json = JsonConvert.SerializeObject(wndPos.Select(d => d.Value).ToArray()); sw.WriteLine(json); } }
internal static void CloseWindow(System.Windows.Window window) { if (window != null) { try { if (window.DataContext != null) { var disposableContext = window.DataContext as IDisposable; if (disposableContext != null) { disposableContext.Dispose(); } } var disposableWindow = window as IDisposable; if (disposableWindow != null) { disposableWindow.Dispose(); } window.Close(); } catch (Exception ex) { LogAndShow("Возникло исключение при закрытии окна", ex , new LogParameter("Тип окна", window.GetType().FullName)); } } else { MessageBox.Show("Не передана ссылка на окно при закрытии"); } }
public void Save(System.Windows.Window form, System.Windows.Controls.TextBox text) { dict[form.GetType().Name + "/" + text.Name] = text.Text; }
public void Load(System.Windows.Window form, System.Windows.Controls.TextBox text) { text.Text = dict[form.GetType().Name + "/" + text.Name]; }
/// <summary> /// 新しいインスタンスを生成します。 /// </summary> /// <param name="window">Application Settings オブジェクトのオーナーを指定します。</param> public WindowSettings(System.Windows.Window window) : base(window.GetType().FullName) { }