From 3dfe0ce59b1dd620bbc7b787d684b8eae6291a4b Mon Sep 17 00:00:00 2001 From: TheXamlGuy Date: Wed, 10 Jul 2024 14:36:09 +0100 Subject: [PATCH] wip --- Wallet.Avalonia/MainView.axaml | 33 +++++++++++++--------- Wallet.Avalonia/WalletNavigationView.axaml | 13 --------- Wallet/MainViewModelActivationHandler.cs | 24 +++++++++++++--- Wallet/OpenWalletViewModel.cs | 13 +++++++++ Wallet/WalletActivatedHandler.cs | 23 +++++++++++++-- 5 files changed, 73 insertions(+), 33 deletions(-) diff --git a/Wallet.Avalonia/MainView.axaml b/Wallet.Avalonia/MainView.axaml index f72da13..4679b8f 100644 --- a/Wallet.Avalonia/MainView.axaml +++ b/Wallet.Avalonia/MainView.axaml @@ -10,8 +10,7 @@ FooterMenuItemsSource="{Binding Footer}" IsSettingsVisible="False" MenuItemTemplate="{Binding Template}" - MenuItemsSource="{Binding SelectedItem}" - SelectionFollowsFocus="True"> + MenuItemsSource="{Binding #ListBox.SelectedItem}"> @@ -31,19 +30,19 @@ + Text="{ReflectionBinding SelectedItem.Name}" /> - - + 40 40 @@ -146,26 +145,26 @@ - - - - - - + + - + @@ -175,14 +174,20 @@ - + + + + - + diff --git a/Wallet.Avalonia/WalletNavigationView.axaml b/Wallet.Avalonia/WalletNavigationView.axaml index 536de48..e6fe981 100644 --- a/Wallet.Avalonia/WalletNavigationView.axaml +++ b/Wallet.Avalonia/WalletNavigationView.axaml @@ -12,19 +12,6 @@ 40 - - - - - - - - - - - - - diff --git a/Wallet/MainViewModelActivationHandler.cs b/Wallet/MainViewModelActivationHandler.cs index cb2fab2..59f75b9 100644 --- a/Wallet/MainViewModelActivationHandler.cs +++ b/Wallet/MainViewModelActivationHandler.cs @@ -11,10 +11,26 @@ public class MainViewModelActivationHandler(IPublisher publisher, { bool selected = true; - foreach (IComponentHost Wallet in Wallets.OrderBy(x => x.Services.GetRequiredService>() - is IConfigurationDescriptor descriptor ? descriptor.Name : null)) + foreach (IComponentHost Wallet in Wallets.OrderBy(x => { - if (Wallet.Services.GetRequiredService>() + IConfigurationDescriptor descriptor = x.Services.GetRequiredService>(); + return descriptor?.Name; + }, + Comparer.Create((x, y) => + { + bool xIsNumeric = int.TryParse(x, out int xNum); + bool yIsNumeric = int.TryParse(y, out int yNum); + + return (xIsNumeric, yIsNumeric) switch + { + (true, true) => xNum.CompareTo(yNum), + (true, false) => -1, + (false, true) => 1, + _ => string.Compare(x, y, StringComparison.Ordinal) + }; + }))) + { + if (Wallet.Services.GetRequiredService>() is IConfigurationDescriptor configuration) { if (Wallet.Services.GetRequiredService() is IServiceFactory factory) @@ -23,7 +39,7 @@ public class MainViewModelActivationHandler(IPublisher publisher, Wallet.Services.GetRequiredService>>(); ProfileImage? profileImage = profileImageDecorator.Value; - if (factory.Create(args => args.Initialize(), configuration.Name, profileImage?.Value ?? null, selected) + if (factory.Create(args => args.Initialize(), configuration.Name, profileImage?.Value ?? null, selected) is WalletNavigationViewModel viewModel) { publisher.Publish(Create.As(viewModel), diff --git a/Wallet/OpenWalletViewModel.cs b/Wallet/OpenWalletViewModel.cs index ec78db2..9948582 100644 --- a/Wallet/OpenWalletViewModel.cs +++ b/Wallet/OpenWalletViewModel.cs @@ -50,4 +50,17 @@ public partial class OpenWalletViewModel : } } } + + + //public override async Task OnActivated() + //{ + // Publisher.Publish(Activated.As()); + // await base.OnActivated(); + //} + + //public override async Task OnDeactivated() + //{ + // Publisher.Publish(Deactivated.As()); + // await base.OnDeactivated(); + //} } \ No newline at end of file diff --git a/Wallet/WalletActivatedHandler.cs b/Wallet/WalletActivatedHandler.cs index 32145ed..f4efb03 100644 --- a/Wallet/WalletActivatedHandler.cs +++ b/Wallet/WalletActivatedHandler.cs @@ -11,8 +11,27 @@ public class WalletActivatedHandler(IWalletHostCollection wallets, { if (args.Sender is Wallet wallet && wallet.Value is IComponentHost host) { - List sortedWallets = [.. wallets.OrderBy(x => x.Services.GetRequiredService>() is - IConfigurationDescriptor descriptor ? descriptor.Name : null)]; + List sortedWallets = + [ + .. wallets.OrderBy(wallet => + { + var descriptor = wallet.Services.GetRequiredService>(); + return descriptor?.Name; + }, + Comparer.Create((x, y) => + { + bool xIsNumeric = int.TryParse(x, out int xNum); + bool yIsNumeric = int.TryParse(y, out int yNum); + + return (xIsNumeric, yIsNumeric) switch + { + (true, true) => xNum.CompareTo(yNum), + (true, false) => -1, + (false, true) => 1, + _ => string.Compare(x, y, StringComparison.Ordinal) + }; + })), + ]; int index = sortedWallets.IndexOf(host);