switched to new way
This commit is contained in:
parent
f22d182c8f
commit
4a65c8e17b
96 changed files with 4991 additions and 10025 deletions
69
src/Poe2Trade.Ui/Views/MainWindow.axaml.cs
Normal file
69
src/Poe2Trade.Ui/Views/MainWindow.axaml.cs
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
using System.Collections.Specialized;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Poe2Trade.Core;
|
||||
using Poe2Trade.Ui.ViewModels;
|
||||
|
||||
namespace Poe2Trade.Ui.Views;
|
||||
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
private ConfigStore? _store;
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void SetConfigStore(ConfigStore store)
|
||||
{
|
||||
_store = store;
|
||||
var s = store.Settings;
|
||||
if (s.WindowWidth.HasValue && s.WindowHeight.HasValue)
|
||||
{
|
||||
Width = s.WindowWidth.Value;
|
||||
Height = s.WindowHeight.Value;
|
||||
}
|
||||
if (s.WindowX.HasValue && s.WindowY.HasValue)
|
||||
{
|
||||
Position = new PixelPoint((int)s.WindowX.Value, (int)s.WindowY.Value);
|
||||
WindowStartupLocation = WindowStartupLocation.Manual;
|
||||
}
|
||||
else
|
||||
{
|
||||
WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnDataContextChanged(EventArgs e)
|
||||
{
|
||||
base.OnDataContextChanged(e);
|
||||
if (DataContext is MainWindowViewModel vm)
|
||||
{
|
||||
vm.Logs.CollectionChanged += (_, args) =>
|
||||
{
|
||||
if (args.Action == NotifyCollectionChangedAction.Add)
|
||||
{
|
||||
var logList = this.FindControl<ListBox>("LogList");
|
||||
if (logList != null && vm.Logs.Count > 0)
|
||||
logList.ScrollIntoView(vm.Logs[^1]);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnClosing(WindowClosingEventArgs e)
|
||||
{
|
||||
if (_store != null)
|
||||
{
|
||||
_store.UpdateSettings(s =>
|
||||
{
|
||||
s.WindowX = Position.X;
|
||||
s.WindowY = Position.Y;
|
||||
s.WindowWidth = Width;
|
||||
s.WindowHeight = Height;
|
||||
});
|
||||
}
|
||||
base.OnClosing(e);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue