Files
XplorePlane/XplorePlane/Views/Debug/DebugPanelWindow.xaml.cs
T
2026-05-18 09:38:29 +08:00

59 lines
1.5 KiB
C#

using System;
using System.ComponentModel;
using System.Windows;
using XplorePlane.Models;
using XplorePlane.ViewModels.Debug;
namespace XplorePlane.Views.Debug
{
public partial class DebugPanelWindow : Window
{
public DebugPanelWindow()
{
InitializeComponent();
Loaded += OnLoaded;
Closing += OnClosing;
}
private DebugPanelViewModel ViewModel => DataContext as DebugPanelViewModel;
private void OnLoaded(object sender, RoutedEventArgs e)
{
ViewModel?.Initialize();
ApplyWindowConfig(ViewModel?.CurrentConfig?.Window);
}
private void OnClosing(object sender, CancelEventArgs e)
{
ViewModel?.SaveWindowConfig(CaptureWindowConfig());
ViewModel?.Dispose();
}
private void ApplyWindowConfig(WindowConfig config)
{
if (config == null)
{
return;
}
Width = config.Width > 0 ? config.Width : Width;
Height = config.Height > 0 ? config.Height : Height;
Left = config.Left;
Top = config.Top;
WindowState = config.State;
}
private WindowConfig CaptureWindowConfig()
{
return new WindowConfig
{
Left = RestoreBounds.Left,
Top = RestoreBounds.Top,
Width = RestoreBounds.Width,
Height = RestoreBounds.Height,
State = WindowState
};
}
}
}