Improve AvaloniaUI startup times
This commit is contained in:
parent
2b6d1201b6
commit
428ea5e864
3 changed files with 120 additions and 60 deletions
|
|
@ -8,11 +8,16 @@ using LibationWinForms.AvaloniaUI.Views.ProductsGrid;
|
|||
using Avalonia.ReactiveUI;
|
||||
using LibationWinForms.AvaloniaUI.ViewModels;
|
||||
using LibationFileManager;
|
||||
using DataLayer;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace LibationWinForms.AvaloniaUI.Views
|
||||
{
|
||||
public partial class MainWindow : ReactiveWindow<MainWindowViewModel>
|
||||
{
|
||||
public event EventHandler Load;
|
||||
public event EventHandler<List<LibraryBook>> LibraryLoaded;
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
|
@ -37,13 +42,9 @@ namespace LibationWinForms.AvaloniaUI.Views
|
|||
// misc which belongs in winforms app but doesn't have a UI element
|
||||
Configure_NonUI();
|
||||
|
||||
async void DoDisplay(object _, EventArgs __)
|
||||
{
|
||||
await productsDisplay.Display();
|
||||
}
|
||||
{
|
||||
this.Load += DoDisplay;
|
||||
LibraryCommands.LibrarySizeChanged += DoDisplay;
|
||||
this.LibraryLoaded += (_, dbBooks) => productsDisplay.Display(dbBooks);
|
||||
LibraryCommands.LibrarySizeChanged += (_, _) => productsDisplay.Display(DbContexts.GetLibrary_Flat_NoTracking(includeParents: true));
|
||||
this.Closing += (_,_) => this.SaveSizeAndLocation(Configuration.Instance);
|
||||
}
|
||||
}
|
||||
|
|
@ -53,9 +54,8 @@ namespace LibationWinForms.AvaloniaUI.Views
|
|||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
|
||||
public event EventHandler Load;
|
||||
|
||||
public void OnLoad() => Load?.Invoke(this, EventArgs.Empty);
|
||||
public void OnLibraryLoaded(List<LibraryBook> initialLibrary) => LibraryLoaded?.Invoke(this, initialLibrary);
|
||||
|
||||
private void FindAllControls()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
using ApplicationServices;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls;
|
||||
using DataLayer;
|
||||
using LibationWinForms.AvaloniaUI.ViewModels;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Avalonia.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LibationWinForms.AvaloniaUI.Views.ProductsGrid
|
||||
{
|
||||
|
|
@ -14,19 +13,17 @@ namespace LibationWinForms.AvaloniaUI.Views.ProductsGrid
|
|||
{
|
||||
private void Configure_Display() { }
|
||||
|
||||
public async Task Display()
|
||||
public void Display(List<LibraryBook> dbBooks)
|
||||
{
|
||||
try
|
||||
{
|
||||
var dbBooks = DbContexts.GetLibrary_Flat_NoTracking(includeParents: true);
|
||||
|
||||
{
|
||||
if (_viewModel is null)
|
||||
{
|
||||
_viewModel = new ProductsDisplayViewModel(dbBooks);
|
||||
await Dispatcher.UIThread.InvokeAsync(() => InitialLoaded?.Invoke(this, EventArgs.Empty));
|
||||
InitialLoaded?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
int bookEntryCount = bindingList.BookEntries().Count();
|
||||
await Dispatcher.UIThread.InvokeAsync(() => VisibleCountChanged?.Invoke(this, bookEntryCount));
|
||||
VisibleCountChanged?.Invoke(this, bookEntryCount);
|
||||
|
||||
//Avalonia displays items in the DataConncetion from an internal copy of
|
||||
//the bound list, not the actual bound list. So we need to reflect to get
|
||||
|
|
@ -53,12 +50,9 @@ namespace LibationWinForms.AvaloniaUI.Views.ProductsGrid
|
|||
//List is already displayed. Replace all items with new ones, refilter, and re-sort
|
||||
string existingFilter = _viewModel?.GridEntries?.Filter;
|
||||
var newEntries = ProductsDisplayViewModel.CreateGridEntries(dbBooks);
|
||||
await Dispatcher.UIThread.InvokeAsync(() =>
|
||||
{
|
||||
bindingList.ReplaceList(newEntries);
|
||||
bindingList.Filter = existingFilter;
|
||||
ReSort();
|
||||
});
|
||||
bindingList.ReplaceList(newEntries);
|
||||
bindingList.Filter = existingFilter;
|
||||
ReSort();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue