From 80651d7b43be12cb9f14d3c46e1b6f99a7211c8b Mon Sep 17 00:00:00 2001 From: LaoSparrow Date: Wed, 23 Apr 2025 22:57:27 +0800 Subject: [PATCH 1/4] feat: basic NavigationService && left panel --- PCL2.Neo/App.axaml.cs | 24 +++++-- PCL2.Neo/PCL2.Neo.csproj | 3 +- PCL2.Neo/Services/NavigationService.cs | 35 ++++++++++ PCL2.Neo/ViewLocator.cs | 66 +++++++++++++----- PCL2.Neo/ViewModels/DownloadViewModel.cs | 24 +++++++ PCL2.Neo/ViewModels/HomeViewModel.cs | 6 ++ PCL2.Neo/ViewModels/MainWindowViewModel.cs | 29 ++++++++ PCL2.Neo/ViewModels/ViewModelBase.cs | 11 ++- PCL2.Neo/Views/DownloadLeftView.axaml | 15 ++++ PCL2.Neo/Views/DownloadLeftView.axaml.cs | 14 ++++ PCL2.Neo/Views/DownloadView.axaml | 29 ++++++++ PCL2.Neo/Views/DownloadView.axaml.cs | 13 ++++ PCL2.Neo/Views/HomeLeftView.axaml | 12 ++++ PCL2.Neo/Views/HomeLeftView.axaml.cs | 14 ++++ PCL2.Neo/Views/HomeView.axaml | 51 ++++++++++++++ PCL2.Neo/Views/HomeView.axaml.cs | 25 +++++++ PCL2.Neo/Views/MainWindow.axaml | 81 +++++++++------------- PCL2.Neo/Views/MainWindow.axaml.cs | 49 ++++++++++--- 18 files changed, 415 insertions(+), 86 deletions(-) create mode 100644 PCL2.Neo/Services/NavigationService.cs create mode 100644 PCL2.Neo/ViewModels/DownloadViewModel.cs create mode 100644 PCL2.Neo/ViewModels/HomeViewModel.cs create mode 100644 PCL2.Neo/Views/DownloadLeftView.axaml create mode 100644 PCL2.Neo/Views/DownloadLeftView.axaml.cs create mode 100644 PCL2.Neo/Views/DownloadView.axaml create mode 100644 PCL2.Neo/Views/DownloadView.axaml.cs create mode 100644 PCL2.Neo/Views/HomeLeftView.axaml create mode 100644 PCL2.Neo/Views/HomeLeftView.axaml.cs create mode 100644 PCL2.Neo/Views/HomeView.axaml create mode 100644 PCL2.Neo/Views/HomeView.axaml.cs diff --git a/PCL2.Neo/App.axaml.cs b/PCL2.Neo/App.axaml.cs index 355c112b..28c1e0d1 100644 --- a/PCL2.Neo/App.axaml.cs +++ b/PCL2.Neo/App.axaml.cs @@ -1,14 +1,14 @@ -using System; using System.Linq; using Avalonia; using Avalonia.Controls.ApplicationLifetimes; -using Avalonia.Data.Core; using Avalonia.Data.Core.Plugins; using Avalonia.Markup.Xaml; -using PCL2.Neo.Helpers; -using PCL2.Neo.Utils; +using CommunityToolkit.Mvvm.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; +using PCL2.Neo.Services; using PCL2.Neo.ViewModels; using PCL2.Neo.Views; +using System; namespace PCL2.Neo { @@ -19,14 +19,28 @@ public override void Initialize() AvaloniaXamlLoader.Load(this); } + private static IServiceProvider ConfigureServices() => new ServiceCollection() + .AddTransient() + .AddTransient() + .AddTransient() + .AddSingleton(s => + new NavigationService(t => (ViewModelBase)s.GetRequiredService(t))) + .BuildServiceProvider(); + public override void OnFrameworkInitializationCompleted() { + Ioc.Default.ConfigureServices(ConfigureServices()); + + var vm = Ioc.Default.GetRequiredService(); if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { // Avoid duplicate validations from both Avalonia and the CommunityToolkit. // More info: https://docs.avaloniaui.net/docs/guides/development-guides/data-validation#manage-validationplugins DisableAvaloniaDataAnnotationValidation(); - desktop.MainWindow = new MainWindow(); + desktop.MainWindow = new MainWindow + { + DataContext = vm + }; } base.OnFrameworkInitializationCompleted(); diff --git a/PCL2.Neo/PCL2.Neo.csproj b/PCL2.Neo/PCL2.Neo.csproj index 1a073dd3..aced6672 100644 --- a/PCL2.Neo/PCL2.Neo.csproj +++ b/PCL2.Neo/PCL2.Neo.csproj @@ -35,8 +35,9 @@ All - + + diff --git a/PCL2.Neo/Services/NavigationService.cs b/PCL2.Neo/Services/NavigationService.cs new file mode 100644 index 00000000..f2612a0c --- /dev/null +++ b/PCL2.Neo/Services/NavigationService.cs @@ -0,0 +1,35 @@ +using PCL2.Neo.ViewModels; +using System; + +namespace PCL2.Neo.Services; + +public class NavigationService +{ + public event Action? CurrentViewModelChanged; + protected readonly Func ViewModelFactory; + + private ViewModelBase? _currentViewModel; + public ViewModelBase? CurrentViewModel + { + get => _currentViewModel; + protected set + { + if (value == _currentViewModel) + return; + _currentViewModel = value; + CurrentViewModelChanged?.Invoke(value); + } + } + + public NavigationService(Func viewModelFactory) + { + ViewModelFactory = viewModelFactory; + } + + public virtual T Goto() where T : ViewModelBase + { + var vm = ViewModelFactory(typeof(T)); + CurrentViewModel = vm; + return (T)vm; + } +} \ No newline at end of file diff --git a/PCL2.Neo/ViewLocator.cs b/PCL2.Neo/ViewLocator.cs index 2fbc639e..796d9a03 100644 --- a/PCL2.Neo/ViewLocator.cs +++ b/PCL2.Neo/ViewLocator.cs @@ -3,28 +3,62 @@ using Avalonia.Controls.Templates; using PCL2.Neo.ViewModels; -namespace PCL2.Neo +namespace PCL2.Neo; + +public class ViewLocator : IDataTemplate { - public class ViewLocator : IDataTemplate + public Control? Build(object? param) { - public Control? Build(object? param) + if (param is null) + return null; + + var name = param.GetType().FullName!.Replace("ViewModel", "View", StringComparison.Ordinal); + var type = Type.GetType(name); + + if (type != null) { - if (param is null) - return null; + return (Control)Activator.CreateInstance(type)!; + } - var name = param.GetType().FullName!.Replace("ViewModel", "View", StringComparison.Ordinal); - var type = Type.GetType(name); + return new TextBlock { Text = "Not Found: " + name }; + } - if (type != null) - { - return (Control)Activator.CreateInstance(type)!; - } + public bool Match(object? data) + { + return data is ViewModelBase; + } +} - return new TextBlock { Text = "Not Found: " + name }; - } - public bool Match(object? data) +public class LeftViewLocator : IDataTemplate +{ + private static string ReplaceLastOccurrence(string text, string oldValue, string newValue) + { + int place = text.LastIndexOf(oldValue, StringComparison.Ordinal); + return place == -1 + ? text + : text.Remove(place, oldValue.Length).Insert(place, newValue); + } + + public Control? Build(object? param) + { + if (param is null) + return null; + + var name = param.GetType().FullName!.Replace("ViewModel", "View", StringComparison.Ordinal); + name = ReplaceLastOccurrence(name, "View", "LeftView"); + var type = Type.GetType(name); + + if (type != null) { - return data is ViewModelBase; + return (Control)Activator.CreateInstance(type)!; } + + // return new TextBlock { Text = "Not Found: " + name }; + return null; } -} + + public bool Match(object? data) + { + return data is ViewModelBase; + } +} \ No newline at end of file diff --git a/PCL2.Neo/ViewModels/DownloadViewModel.cs b/PCL2.Neo/ViewModels/DownloadViewModel.cs new file mode 100644 index 00000000..d5e435ce --- /dev/null +++ b/PCL2.Neo/ViewModels/DownloadViewModel.cs @@ -0,0 +1,24 @@ +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; + +namespace PCL2.Neo.ViewModels; + +public partial class DownloadViewModel : ViewModelBase +{ + public override bool IsPaneVisible => true; + + [ObservableProperty] + private string _message = "I am from DownloadViewModel"; + + [RelayCommand] + private void Btn_Test1() + { + Message = "I am from DownloadViewModel Test1"; + } + + [RelayCommand] + private void Btn_Test2() + { + Message = "I am from DownloadViewModel Test2"; + } +} \ No newline at end of file diff --git a/PCL2.Neo/ViewModels/HomeViewModel.cs b/PCL2.Neo/ViewModels/HomeViewModel.cs new file mode 100644 index 00000000..39e36c90 --- /dev/null +++ b/PCL2.Neo/ViewModels/HomeViewModel.cs @@ -0,0 +1,6 @@ +namespace PCL2.Neo.ViewModels; + +public class HomeViewModel : ViewModelBase +{ + +} \ No newline at end of file diff --git a/PCL2.Neo/ViewModels/MainWindowViewModel.cs b/PCL2.Neo/ViewModels/MainWindowViewModel.cs index 3251f5f0..63eabae7 100644 --- a/PCL2.Neo/ViewModels/MainWindowViewModel.cs +++ b/PCL2.Neo/ViewModels/MainWindowViewModel.cs @@ -1,20 +1,49 @@ using Avalonia.Controls; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; using PCL2.Neo.Controls.MyMsg; +using PCL2.Neo.Services; namespace PCL2.Neo.ViewModels { public partial class MainWindowViewModel : ViewModelBase { private Window? _window; + public NavigationService NavigationService { get; } + + [ObservableProperty] + private ViewModelBase? _currentViewModel; // 为了设计时的DataContext public MainWindowViewModel() { + throw new System.NotImplementedException(); } public MainWindowViewModel(Window window) { this._window = window; } + public MainWindowViewModel(NavigationService navigationService) + { + this.NavigationService = navigationService; + this.NavigationService.CurrentViewModelChanged += x => + { + CurrentViewModel = x; + }; + this.NavigationService.Goto(); + } + + [RelayCommand] + public void NavigateToHome() + { + this.NavigationService.Goto(); + } + + [RelayCommand] + public void NavigateToDownload() + { + this.NavigationService.Goto(); + } public void Close() { diff --git a/PCL2.Neo/ViewModels/ViewModelBase.cs b/PCL2.Neo/ViewModels/ViewModelBase.cs index 5ef648a5..06c06e9d 100644 --- a/PCL2.Neo/ViewModels/ViewModelBase.cs +++ b/PCL2.Neo/ViewModels/ViewModelBase.cs @@ -1,9 +1,8 @@ using CommunityToolkit.Mvvm.ComponentModel; -namespace PCL2.Neo.ViewModels -{ - public class ViewModelBase : ObservableObject - { +namespace PCL2.Neo.ViewModels; - } -} +public class ViewModelBase : ObservableObject +{ + public virtual bool IsPaneVisible => false; +} \ No newline at end of file diff --git a/PCL2.Neo/Views/DownloadLeftView.axaml b/PCL2.Neo/Views/DownloadLeftView.axaml new file mode 100644 index 00000000..971c53b6 --- /dev/null +++ b/PCL2.Neo/Views/DownloadLeftView.axaml @@ -0,0 +1,15 @@ + + + + + + + diff --git a/PCL2.Neo/Views/DownloadLeftView.axaml.cs b/PCL2.Neo/Views/DownloadLeftView.axaml.cs new file mode 100644 index 00000000..76b35c01 --- /dev/null +++ b/PCL2.Neo/Views/DownloadLeftView.axaml.cs @@ -0,0 +1,14 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; + +namespace PCL2.Neo.Views +{ + public partial class DownloadLeftView : UserControl + { + public DownloadLeftView() + { + InitializeComponent(); + } + } +} \ No newline at end of file diff --git a/PCL2.Neo/Views/DownloadView.axaml b/PCL2.Neo/Views/DownloadView.axaml new file mode 100644 index 00000000..f0542ae8 --- /dev/null +++ b/PCL2.Neo/Views/DownloadView.axaml @@ -0,0 +1,29 @@ + + + + + + + + + + + diff --git a/PCL2.Neo/Views/DownloadView.axaml.cs b/PCL2.Neo/Views/DownloadView.axaml.cs new file mode 100644 index 00000000..fd595da4 --- /dev/null +++ b/PCL2.Neo/Views/DownloadView.axaml.cs @@ -0,0 +1,13 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; + +namespace PCL2.Neo.Views; + +public partial class DownloadView : UserControl +{ + public DownloadView() + { + InitializeComponent(); + } +} \ No newline at end of file diff --git a/PCL2.Neo/Views/HomeLeftView.axaml b/PCL2.Neo/Views/HomeLeftView.axaml new file mode 100644 index 00000000..f9bd20fb --- /dev/null +++ b/PCL2.Neo/Views/HomeLeftView.axaml @@ -0,0 +1,12 @@ + + Welcome to Avalonia!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + + diff --git a/PCL2.Neo/Views/HomeLeftView.axaml.cs b/PCL2.Neo/Views/HomeLeftView.axaml.cs new file mode 100644 index 00000000..16ced31a --- /dev/null +++ b/PCL2.Neo/Views/HomeLeftView.axaml.cs @@ -0,0 +1,14 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; + +namespace PCL2.Neo.Views +{ + public partial class HomeLeftView : UserControl + { + public HomeLeftView() + { + InitializeComponent(); + } + } +} \ No newline at end of file diff --git a/PCL2.Neo/Views/HomeView.axaml b/PCL2.Neo/Views/HomeView.axaml new file mode 100644 index 00000000..f3a2feab --- /dev/null +++ b/PCL2.Neo/Views/HomeView.axaml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PCL2.Neo/Views/HomeView.axaml.cs b/PCL2.Neo/Views/HomeView.axaml.cs new file mode 100644 index 00000000..3eca9783 --- /dev/null +++ b/PCL2.Neo/Views/HomeView.axaml.cs @@ -0,0 +1,25 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Interactivity; +using Avalonia.Markup.Xaml; +using PCL2.Neo.Controls; + +namespace PCL2.Neo.Views; + +public partial class HomeView : UserControl +{ + public HomeView() + { + InitializeComponent(); + } + + private void Button_OnClick(object? sender, RoutedEventArgs e) + { + this.TestLoading.State = MyLoading.LoadingState.Loading; + } + + private void Button2_OnClick(object? sender, RoutedEventArgs e) + { + this.TestLoading.State = MyLoading.LoadingState.Error; + } +} \ No newline at end of file diff --git a/PCL2.Neo/Views/MainWindow.axaml b/PCL2.Neo/Views/MainWindow.axaml index abc4baa2..1850c478 100644 --- a/PCL2.Neo/Views/MainWindow.axaml +++ b/PCL2.Neo/Views/MainWindow.axaml @@ -16,7 +16,10 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:pc="using:PCL2.Neo.Controls" - xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> + xmlns:vm="using:PCL2.Neo.ViewModels" + xmlns:local="using:PCL2.Neo" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + x:DataType="vm:MainWindowViewModel"> + ZIndex="3"> + ZIndex="3"> + Text="{DynamicResource LangTitleHome}" + Command="{Binding NavigateToHome}" /> + Text="{DynamicResource LangTitleDownload}" + Command="{Binding NavigateToDownload}" /> - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + ZIndex="10" /> diff --git a/PCL2.Neo/Views/MainWindow.axaml.cs b/PCL2.Neo/Views/MainWindow.axaml.cs index 1294acab..e3500b02 100644 --- a/PCL2.Neo/Views/MainWindow.axaml.cs +++ b/PCL2.Neo/Views/MainWindow.axaml.cs @@ -1,14 +1,25 @@ using Avalonia; +using Avalonia.Animation; using Avalonia.Animation.Easings; using Avalonia.Controls; +using Avalonia.Controls.Presenters; +using Avalonia.Controls.Templates; using Avalonia.Interactivity; using Avalonia.Media; +using Avalonia.Rendering.Composition; +using Avalonia.Styling; using PCL2.Neo.Animations; using PCL2.Neo.Animations.Easings; using PCL2.Neo.Controls; using PCL2.Neo.Helpers; +using PCL2.Neo.ViewModels; using System; +using System.Linq; +using System.Security.Cryptography; using System.Threading.Tasks; +using BounceEaseOut = Avalonia.Animation.Easings.BounceEaseOut; +using CubicEaseOut = Avalonia.Animation.Easings.CubicEaseOut; +using ExponentialEaseOut = Avalonia.Animation.Easings.ExponentialEaseOut; namespace PCL2.Neo.Views; @@ -30,8 +41,36 @@ public MainWindow() BtnTitleMin.Click += (_, _) => WindowState = WindowState.Minimized; + LeftNavigationControl.Loaded += (_, _) => + { + LeftNavigationControlBorder.Width = LeftNavigationControl.Presenter!.Child?.Width ?? 0d; + AnimationHelper? lastAnimation = null; + LeftNavigationControl.Presenter!.PropertyChanged += async (_, e) => + { + if (e.Property != ContentPresenter.ChildProperty) + return; + var oldValue = e.OldValue as Control; + var newValue = e.NewValue as Control; + lastAnimation?.CancelAndClear(); + var previousScaleTransform = + (LeftNavigationControlBorder.RenderTransform as TransformGroup)?.Children + .FirstOrDefault(x => x is ScaleTransform) as ScaleTransform; + var previousScaleX = previousScaleTransform?.ScaleX ?? 1d; + LeftNavigationControlBorder.Width = LeftNavigationControl.Presenter!.Child?.Width ?? 0d; + var scale = oldValue?.Width / newValue?.Width * previousScaleX ?? 1d; + lastAnimation = new AnimationHelper( + [ + new ScaleTransformScaleXAnimation(LeftNavigationControlBorder, TimeSpan.FromMilliseconds(300), scale, + 1d, new CubicEaseOut()) + ]); + await lastAnimation.RunAsync(); + }; + }; + + AnimationIn(); } + private void OnNavPointerPressed(object? sender, Avalonia.Input.PointerPressedEventArgs e) { this.BeginMoveDrag(e); @@ -67,14 +106,4 @@ private async Task AnimationOut() await animation.RunAsync(); } } - - private void Button_OnClick(object? sender, RoutedEventArgs e) - { - this.TestLoading.State = MyLoading.LoadingState.Loading; - } - - private void Button2_OnClick(object? sender, RoutedEventArgs e) - { - this.TestLoading.State = MyLoading.LoadingState.Error; - } } \ No newline at end of file From d4d34b42306d0823ff8b7b89de94eeefb3a37055 Mon Sep 17 00:00:00 2001 From: LaoSparrow Date: Tue, 29 Apr 2025 01:39:09 +0800 Subject: [PATCH 2/4] chore: fix broken build && revert deletion of java search test btn --- PCL2.Neo/PCL2.Neo.csproj | 12 ----------- PCL2.Neo/Views/HomeView.axaml | 2 +- PCL2.Neo/Views/HomeView.axaml.cs | 34 ++++++++++++++++++++++++++++++ PCL2.Neo/Views/MainWindow.axaml.cs | 17 +-------------- 4 files changed, 36 insertions(+), 29 deletions(-) diff --git a/PCL2.Neo/PCL2.Neo.csproj b/PCL2.Neo/PCL2.Neo.csproj index ad9dd98c..8d295d8a 100644 --- a/PCL2.Neo/PCL2.Neo.csproj +++ b/PCL2.Neo/PCL2.Neo.csproj @@ -34,20 +34,8 @@ None All -<<<<<<< HEAD - -======= ->>>>>>> main - - - - - - - - diff --git a/PCL2.Neo/Views/HomeView.axaml b/PCL2.Neo/Views/HomeView.axaml index f3a2feab..cde008df 100644 --- a/PCL2.Neo/Views/HomeView.axaml +++ b/PCL2.Neo/Views/HomeView.axaml @@ -44,7 +44,7 @@ Name="TestLoading" Width="150" /> - + diff --git a/PCL2.Neo/Views/HomeView.axaml.cs b/PCL2.Neo/Views/HomeView.axaml.cs index 3eca9783..798e8ad4 100644 --- a/PCL2.Neo/Views/HomeView.axaml.cs +++ b/PCL2.Neo/Views/HomeView.axaml.cs @@ -3,6 +3,9 @@ using Avalonia.Interactivity; using Avalonia.Markup.Xaml; using PCL2.Neo.Controls; +using PCL2.Neo.Models.Minecraft.Java; +using System; +using System.Linq; namespace PCL2.Neo.Views; @@ -22,4 +25,35 @@ private void Button2_OnClick(object? sender, RoutedEventArgs e) { this.TestLoading.State = MyLoading.LoadingState.Error; } + + private async void Search_Java_Button(object? sender, RoutedEventArgs e) + { + try + { + var javas = await Java.SearchJava(); + Console.WriteLine($"找到 {javas.Count()} 个Java环境:"); + + foreach (var java in javas) + { + try + { + Console.WriteLine("----------------------"); + Console.WriteLine($"路径: {java.DirectoryPath}"); + var version = java.Version; + Console.WriteLine($"版本: Java {version}"); + Console.WriteLine($"位数: {(java.Is64Bit ? "64位" : "32位")}"); + Console.WriteLine($"类型: {(java.IsJre ? "JRE" : "JDK")}"); + Console.WriteLine($"可用: {java.Compability}"); + } + catch (Exception ex) + { + Console.WriteLine($"处理Java信息时出错: {ex.Message}"); + } + } + } + catch (Exception ex) + { + Console.WriteLine($"搜索失败: {ex.Message}"); + } + } } \ No newline at end of file diff --git a/PCL2.Neo/Views/MainWindow.axaml.cs b/PCL2.Neo/Views/MainWindow.axaml.cs index 9284c8c5..01e42edf 100644 --- a/PCL2.Neo/Views/MainWindow.axaml.cs +++ b/PCL2.Neo/Views/MainWindow.axaml.cs @@ -1,22 +1,17 @@ using Avalonia; using Avalonia.Animation.Easings; using Avalonia.Controls; +using Avalonia.Controls.Presenters; using Avalonia.Interactivity; using Avalonia.Media; using PCL2.Neo.Animations; using PCL2.Neo.Animations.Easings; using PCL2.Neo.Controls; using PCL2.Neo.Helpers; -using PCL2.Neo.ViewModels; -using PCL2.Neo.Models.Minecraft.Java; using System; using System.Linq; -using System.Security.Cryptography; -using System.Linq; using System.Threading.Tasks; -using BounceEaseOut = Avalonia.Animation.Easings.BounceEaseOut; using CubicEaseOut = Avalonia.Animation.Easings.CubicEaseOut; -using ExponentialEaseOut = Avalonia.Animation.Easings.ExponentialEaseOut; namespace PCL2.Neo.Views; @@ -103,14 +98,4 @@ private async Task AnimationOut() await animation.RunAsync(); } } - - private void Button_OnClick(object? sender, RoutedEventArgs e) - { - this.TestLoading.State = MyLoading.LoadingState.Loading; - } - - private void Button2_OnClick(object? sender, RoutedEventArgs e) - { - this.TestLoading.State = MyLoading.LoadingState.Error; - } } \ No newline at end of file From c10bba3e535a2de3d283e40091bd927f9b61248d Mon Sep 17 00:00:00 2001 From: LaoSparrow Date: Sat, 3 May 2025 02:33:30 +0800 Subject: [PATCH 3/4] feat(NavigationService): navigating sub views --- PCL2.Neo/App.axaml.cs | 11 +++- PCL2.Neo/Attributes.cs | 15 +++++ PCL2.Neo/PCL2.Neo.csproj | 18 ++++++ PCL2.Neo/Services/NavigationService.cs | 60 +++++++++++++++++-- PCL2.Neo/ViewLocator.cs | 34 ----------- .../Download/DownloadGameViewModel.cs | 7 +++ .../Download/DownloadModViewModel.cs | 7 +++ PCL2.Neo/ViewModels/DownloadViewModel.cs | 22 ++++++- PCL2.Neo/ViewModels/Home/HomeSubViewModel.cs | 22 +++++++ PCL2.Neo/ViewModels/HomeViewModel.cs | 3 + PCL2.Neo/ViewModels/MainWindowViewModel.cs | 22 +++++++ PCL2.Neo/ViewModels/ViewModelBase.cs | 4 +- .../Views/Download/DownloadGameView.axaml | 18 ++++++ .../Views/Download/DownloadGameView.axaml.cs | 11 ++++ PCL2.Neo/Views/Download/DownloadModView.axaml | 18 ++++++ .../Views/Download/DownloadModView.axaml.cs | 11 ++++ PCL2.Neo/Views/DownloadLeftView.axaml | 15 ----- PCL2.Neo/Views/DownloadLeftView.axaml.cs | 14 ----- PCL2.Neo/Views/DownloadView.axaml | 33 ++++++---- PCL2.Neo/Views/DownloadView.axaml.cs | 11 ++-- PCL2.Neo/Views/Home/HomeSubView.axaml | 52 ++++++++++++++++ PCL2.Neo/Views/Home/HomeSubView.axaml.cs | 57 ++++++++++++++++++ PCL2.Neo/Views/HomeLeftView.axaml | 12 ---- PCL2.Neo/Views/HomeLeftView.axaml.cs | 14 ----- PCL2.Neo/Views/HomeView.axaml | 50 ++-------------- PCL2.Neo/Views/HomeView.axaml.cs | 53 ++-------------- PCL2.Neo/Views/MainWindow.axaml | 18 +++--- 27 files changed, 393 insertions(+), 219 deletions(-) create mode 100644 PCL2.Neo/Attributes.cs create mode 100644 PCL2.Neo/ViewModels/Download/DownloadGameViewModel.cs create mode 100644 PCL2.Neo/ViewModels/Download/DownloadModViewModel.cs create mode 100644 PCL2.Neo/ViewModels/Home/HomeSubViewModel.cs create mode 100644 PCL2.Neo/Views/Download/DownloadGameView.axaml create mode 100644 PCL2.Neo/Views/Download/DownloadGameView.axaml.cs create mode 100644 PCL2.Neo/Views/Download/DownloadModView.axaml create mode 100644 PCL2.Neo/Views/Download/DownloadModView.axaml.cs delete mode 100644 PCL2.Neo/Views/DownloadLeftView.axaml delete mode 100644 PCL2.Neo/Views/DownloadLeftView.axaml.cs create mode 100644 PCL2.Neo/Views/Home/HomeSubView.axaml create mode 100644 PCL2.Neo/Views/Home/HomeSubView.axaml.cs delete mode 100644 PCL2.Neo/Views/HomeLeftView.axaml delete mode 100644 PCL2.Neo/Views/HomeLeftView.axaml.cs diff --git a/PCL2.Neo/App.axaml.cs b/PCL2.Neo/App.axaml.cs index 28c1e0d1..f6f5c083 100644 --- a/PCL2.Neo/App.axaml.cs +++ b/PCL2.Neo/App.axaml.cs @@ -7,6 +7,8 @@ using Microsoft.Extensions.DependencyInjection; using PCL2.Neo.Services; using PCL2.Neo.ViewModels; +using PCL2.Neo.ViewModels.Download; +using PCL2.Neo.ViewModels.Home; using PCL2.Neo.Views; using System; @@ -21,10 +23,15 @@ public override void Initialize() private static IServiceProvider ConfigureServices() => new ServiceCollection() .AddTransient() + .AddTransient() + .AddTransient() + .AddTransient() - .AddSingleton(s => - new NavigationService(t => (ViewModelBase)s.GetRequiredService(t))) + .AddTransient() + .AddTransient() + + .AddSingleton(s => new NavigationService(s)) .BuildServiceProvider(); public override void OnFrameworkInitializationCompleted() diff --git a/PCL2.Neo/Attributes.cs b/PCL2.Neo/Attributes.cs new file mode 100644 index 00000000..852b2850 --- /dev/null +++ b/PCL2.Neo/Attributes.cs @@ -0,0 +1,15 @@ +using System; + +namespace PCL2.Neo; + +[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)] +public class SubViewModelOfAttribute(Type parentViewModel) : Attribute +{ + public Type ParentViewModel { get; } = parentViewModel; +} + +[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)] +public class DefaultSubViewModelAttribute(Type subViewModel) : Attribute +{ + public Type SubViewModel { get; } = subViewModel; +} \ No newline at end of file diff --git a/PCL2.Neo/PCL2.Neo.csproj b/PCL2.Neo/PCL2.Neo.csproj index 8d295d8a..fb82ff64 100644 --- a/PCL2.Neo/PCL2.Neo.csproj +++ b/PCL2.Neo/PCL2.Neo.csproj @@ -47,4 +47,22 @@ + + + + HomeLeftView.axaml + + + HomeRightView.axaml + Code + + + DownloadRightView.axaml + Code + + + DownloadModView.axaml + Code + + diff --git a/PCL2.Neo/Services/NavigationService.cs b/PCL2.Neo/Services/NavigationService.cs index f2612a0c..d68cc854 100644 --- a/PCL2.Neo/Services/NavigationService.cs +++ b/PCL2.Neo/Services/NavigationService.cs @@ -1,12 +1,16 @@ +using Microsoft.Extensions.DependencyInjection; using PCL2.Neo.ViewModels; using System; +using System.Reflection; namespace PCL2.Neo.Services; public class NavigationService { + public IServiceProvider ServiceProvider { get; init; } + public event Action? CurrentViewModelChanged; - protected readonly Func ViewModelFactory; + public event Action? CurrentSubViewModelChanged; private ViewModelBase? _currentViewModel; public ViewModelBase? CurrentViewModel @@ -21,15 +25,59 @@ protected set } } - public NavigationService(Func viewModelFactory) + private ViewModelBase? _currentSubViewModel; + public ViewModelBase? CurrentSubViewModel + { + get => _currentSubViewModel; + protected set + { + if (value == _currentSubViewModel) + return; + _currentSubViewModel = value; + CurrentSubViewModelChanged?.Invoke(value); + } + } + + public NavigationService(IServiceProvider serviceProvider) { - ViewModelFactory = viewModelFactory; + ServiceProvider = serviceProvider; } public virtual T Goto() where T : ViewModelBase { - var vm = ViewModelFactory(typeof(T)); - CurrentViewModel = vm; - return (T)vm; + if (typeof(T).GetCustomAttribute() is { } dsvm) + { + var vm = CurrentViewModel as T; + if (vm?.GetType() != typeof(T)) + { + vm = ServiceProvider.GetRequiredService(); + CurrentViewModel = vm; + } + if (CurrentSubViewModel?.GetType() != dsvm.SubViewModel) + CurrentSubViewModel = ServiceProvider.GetRequiredService(dsvm.SubViewModel) as ViewModelBase; + return vm; + } + + if (typeof(T).GetCustomAttribute() is { } svmo) + { + var subVm = CurrentSubViewModel as T; + if (CurrentViewModel?.GetType() != svmo.ParentViewModel) + CurrentViewModel = ServiceProvider.GetRequiredService(svmo.ParentViewModel) as ViewModelBase; + if (subVm?.GetType() != typeof(T)) + { + subVm = ServiceProvider.GetRequiredService(); + CurrentSubViewModel = subVm; + } + return subVm; + } + + var targetVm = CurrentViewModel?.GetType() != typeof(T) || CurrentSubViewModel?.GetType() != typeof(T) + ? ServiceProvider.GetRequiredService() + : (T)CurrentViewModel; + if (CurrentViewModel?.GetType() != typeof(T)) + CurrentViewModel = targetVm; + if (CurrentSubViewModel?.GetType() != typeof(T)) + CurrentSubViewModel = targetVm; + return targetVm; } } \ No newline at end of file diff --git a/PCL2.Neo/ViewLocator.cs b/PCL2.Neo/ViewLocator.cs index 796d9a03..9aecab0b 100644 --- a/PCL2.Neo/ViewLocator.cs +++ b/PCL2.Neo/ViewLocator.cs @@ -23,40 +23,6 @@ public class ViewLocator : IDataTemplate return new TextBlock { Text = "Not Found: " + name }; } - public bool Match(object? data) - { - return data is ViewModelBase; - } -} - -public class LeftViewLocator : IDataTemplate -{ - private static string ReplaceLastOccurrence(string text, string oldValue, string newValue) - { - int place = text.LastIndexOf(oldValue, StringComparison.Ordinal); - return place == -1 - ? text - : text.Remove(place, oldValue.Length).Insert(place, newValue); - } - - public Control? Build(object? param) - { - if (param is null) - return null; - - var name = param.GetType().FullName!.Replace("ViewModel", "View", StringComparison.Ordinal); - name = ReplaceLastOccurrence(name, "View", "LeftView"); - var type = Type.GetType(name); - - if (type != null) - { - return (Control)Activator.CreateInstance(type)!; - } - - // return new TextBlock { Text = "Not Found: " + name }; - return null; - } - public bool Match(object? data) { return data is ViewModelBase; diff --git a/PCL2.Neo/ViewModels/Download/DownloadGameViewModel.cs b/PCL2.Neo/ViewModels/Download/DownloadGameViewModel.cs new file mode 100644 index 00000000..90522970 --- /dev/null +++ b/PCL2.Neo/ViewModels/Download/DownloadGameViewModel.cs @@ -0,0 +1,7 @@ +namespace PCL2.Neo.ViewModels.Download; + +[SubViewModelOf(typeof(DownloadViewModel))] +public class DownloadGameViewModel : ViewModelBase +{ + +} \ No newline at end of file diff --git a/PCL2.Neo/ViewModels/Download/DownloadModViewModel.cs b/PCL2.Neo/ViewModels/Download/DownloadModViewModel.cs new file mode 100644 index 00000000..7f724923 --- /dev/null +++ b/PCL2.Neo/ViewModels/Download/DownloadModViewModel.cs @@ -0,0 +1,7 @@ +namespace PCL2.Neo.ViewModels.Download; + +[SubViewModelOf(typeof(DownloadViewModel))] +public class DownloadModViewModel : ViewModelBase +{ + +} \ No newline at end of file diff --git a/PCL2.Neo/ViewModels/DownloadViewModel.cs b/PCL2.Neo/ViewModels/DownloadViewModel.cs index d5e435ce..e687a306 100644 --- a/PCL2.Neo/ViewModels/DownloadViewModel.cs +++ b/PCL2.Neo/ViewModels/DownloadViewModel.cs @@ -1,15 +1,35 @@ using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; +using PCL2.Neo.Services; +using PCL2.Neo.ViewModels.Download; namespace PCL2.Neo.ViewModels; +[DefaultSubViewModel(typeof(DownloadGameViewModel))] public partial class DownloadViewModel : ViewModelBase { - public override bool IsPaneVisible => true; + public NavigationService NavigationService { get; } [ObservableProperty] private string _message = "I am from DownloadViewModel"; + public DownloadViewModel(NavigationService navigationService) + { + NavigationService = navigationService; + } + + [RelayCommand] + private void NavigateToDownloadGame() + { + this.NavigationService.Goto(); + } + + [RelayCommand] + private void NavigateToDownloadMod() + { + this.NavigationService.Goto(); + } + [RelayCommand] private void Btn_Test1() { diff --git a/PCL2.Neo/ViewModels/Home/HomeSubViewModel.cs b/PCL2.Neo/ViewModels/Home/HomeSubViewModel.cs new file mode 100644 index 00000000..96d2c784 --- /dev/null +++ b/PCL2.Neo/ViewModels/Home/HomeSubViewModel.cs @@ -0,0 +1,22 @@ +using CommunityToolkit.Mvvm.Input; +using PCL2.Neo.Services; +using PCL2.Neo.ViewModels.Download; + +namespace PCL2.Neo.ViewModels.Home; + +[SubViewModelOf(typeof(HomeViewModel))] +public partial class HomeSubViewModel : ViewModelBase +{ + public NavigationService NavigationService { get; } + + public HomeSubViewModel(NavigationService navigationService) + { + this.NavigationService = navigationService; + } + + [RelayCommand] + private void NavigateToDownloadMod() + { + this.NavigationService.Goto(); + } +} \ No newline at end of file diff --git a/PCL2.Neo/ViewModels/HomeViewModel.cs b/PCL2.Neo/ViewModels/HomeViewModel.cs index 39e36c90..2a2e23c0 100644 --- a/PCL2.Neo/ViewModels/HomeViewModel.cs +++ b/PCL2.Neo/ViewModels/HomeViewModel.cs @@ -1,5 +1,8 @@ +using PCL2.Neo.ViewModels.Home; + namespace PCL2.Neo.ViewModels; +[DefaultSubViewModel(typeof(HomeSubViewModel))] public class HomeViewModel : ViewModelBase { diff --git a/PCL2.Neo/ViewModels/MainWindowViewModel.cs b/PCL2.Neo/ViewModels/MainWindowViewModel.cs index 63eabae7..5c60e2a8 100644 --- a/PCL2.Neo/ViewModels/MainWindowViewModel.cs +++ b/PCL2.Neo/ViewModels/MainWindowViewModel.cs @@ -11,8 +11,17 @@ public partial class MainWindowViewModel : ViewModelBase private Window? _window; public NavigationService NavigationService { get; } + // quite shitty, maybe consider using enum and converters + [ObservableProperty] private bool _isNavBtn1Checked = true; + [ObservableProperty] private bool _isNavBtn2Checked; + [ObservableProperty] private bool _isNavBtn3Checked; + [ObservableProperty] private bool _isNavBtn4Checked; + [ObservableProperty] private bool _isNavBtn5Checked; + [ObservableProperty] private ViewModelBase? _currentViewModel; + [ObservableProperty] + private ViewModelBase? _currentSubViewModel; // 为了设计时的DataContext public MainWindowViewModel() @@ -29,6 +38,19 @@ public MainWindowViewModel(NavigationService navigationService) this.NavigationService.CurrentViewModelChanged += x => { CurrentViewModel = x; + switch (x) + { + case HomeViewModel: + IsNavBtn1Checked = true; + break; + case DownloadViewModel: + IsNavBtn2Checked = true; + break; + } + }; + this.NavigationService.CurrentSubViewModelChanged += x => + { + CurrentSubViewModel = x; }; this.NavigationService.Goto(); } diff --git a/PCL2.Neo/ViewModels/ViewModelBase.cs b/PCL2.Neo/ViewModels/ViewModelBase.cs index 06c06e9d..515c3506 100644 --- a/PCL2.Neo/ViewModels/ViewModelBase.cs +++ b/PCL2.Neo/ViewModels/ViewModelBase.cs @@ -2,7 +2,7 @@ namespace PCL2.Neo.ViewModels; -public class ViewModelBase : ObservableObject +public partial class ViewModelBase : ObservableObject { - public virtual bool IsPaneVisible => false; + } \ No newline at end of file diff --git a/PCL2.Neo/Views/Download/DownloadGameView.axaml b/PCL2.Neo/Views/Download/DownloadGameView.axaml new file mode 100644 index 00000000..da02522c --- /dev/null +++ b/PCL2.Neo/Views/Download/DownloadGameView.axaml @@ -0,0 +1,18 @@ + + + + + + + + + diff --git a/PCL2.Neo/Views/Download/DownloadGameView.axaml.cs b/PCL2.Neo/Views/Download/DownloadGameView.axaml.cs new file mode 100644 index 00000000..4c66f950 --- /dev/null +++ b/PCL2.Neo/Views/Download/DownloadGameView.axaml.cs @@ -0,0 +1,11 @@ +using Avalonia.Controls; + +namespace PCL2.Neo.Views.Download; + +public partial class DownloadGameView : UserControl +{ + public DownloadGameView() + { + InitializeComponent(); + } +} \ No newline at end of file diff --git a/PCL2.Neo/Views/Download/DownloadModView.axaml b/PCL2.Neo/Views/Download/DownloadModView.axaml new file mode 100644 index 00000000..1afd2255 --- /dev/null +++ b/PCL2.Neo/Views/Download/DownloadModView.axaml @@ -0,0 +1,18 @@ + + + + + + + + + diff --git a/PCL2.Neo/Views/Download/DownloadModView.axaml.cs b/PCL2.Neo/Views/Download/DownloadModView.axaml.cs new file mode 100644 index 00000000..ae693946 --- /dev/null +++ b/PCL2.Neo/Views/Download/DownloadModView.axaml.cs @@ -0,0 +1,11 @@ +using Avalonia.Controls; + +namespace PCL2.Neo.Views.Download; + +public partial class DownloadModView : UserControl +{ + public DownloadModView() + { + InitializeComponent(); + } +} \ No newline at end of file diff --git a/PCL2.Neo/Views/DownloadLeftView.axaml b/PCL2.Neo/Views/DownloadLeftView.axaml deleted file mode 100644 index 971c53b6..00000000 --- a/PCL2.Neo/Views/DownloadLeftView.axaml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - diff --git a/PCL2.Neo/Views/DownloadLeftView.axaml.cs b/PCL2.Neo/Views/DownloadLeftView.axaml.cs deleted file mode 100644 index 76b35c01..00000000 --- a/PCL2.Neo/Views/DownloadLeftView.axaml.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Avalonia; -using Avalonia.Controls; -using Avalonia.Markup.Xaml; - -namespace PCL2.Neo.Views -{ - public partial class DownloadLeftView : UserControl - { - public DownloadLeftView() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/PCL2.Neo/Views/DownloadView.axaml b/PCL2.Neo/Views/DownloadView.axaml index f0542ae8..cef8a615 100644 --- a/PCL2.Neo/Views/DownloadView.axaml +++ b/PCL2.Neo/Views/DownloadView.axaml @@ -4,25 +4,36 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:pc="using:PCL2.Neo.Controls" xmlns:vm="using:PCL2.Neo.ViewModels" - mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" + mc:Ignorable="d" d:DesignWidth="150" d:DesignHeight="450" x:Class="PCL2.Neo.Views.DownloadView" - x:DataType="vm:DownloadViewModel"> - - - - - + x:DataType="vm:DownloadViewModel" + Width="170"> + + + + Command="{Binding NavigateToDownloadGameCommand}"/> + + diff --git a/PCL2.Neo/Views/DownloadView.axaml.cs b/PCL2.Neo/Views/DownloadView.axaml.cs index fd595da4..b1eb0768 100644 --- a/PCL2.Neo/Views/DownloadView.axaml.cs +++ b/PCL2.Neo/Views/DownloadView.axaml.cs @@ -2,12 +2,13 @@ using Avalonia.Controls; using Avalonia.Markup.Xaml; -namespace PCL2.Neo.Views; - -public partial class DownloadView : UserControl +namespace PCL2.Neo.Views { - public DownloadView() + public partial class DownloadView : UserControl { - InitializeComponent(); + public DownloadView() + { + InitializeComponent(); + } } } \ No newline at end of file diff --git a/PCL2.Neo/Views/Home/HomeSubView.axaml b/PCL2.Neo/Views/Home/HomeSubView.axaml new file mode 100644 index 00000000..dbb67cc9 --- /dev/null +++ b/PCL2.Neo/Views/Home/HomeSubView.axaml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PCL2.Neo/Views/Home/HomeSubView.axaml.cs b/PCL2.Neo/Views/Home/HomeSubView.axaml.cs new file mode 100644 index 00000000..e48a6a4f --- /dev/null +++ b/PCL2.Neo/Views/Home/HomeSubView.axaml.cs @@ -0,0 +1,57 @@ +using Avalonia.Controls; +using Avalonia.Interactivity; +using PCL2.Neo.Controls; +using PCL2.Neo.Models.Minecraft.Java; +using System; +using System.Linq; + +namespace PCL2.Neo.Views.Home; + +public partial class HomeSubView : UserControl +{ + public HomeSubView() + { + InitializeComponent(); + } + + private void Button_OnClick(object? sender, RoutedEventArgs e) + { + this.TestLoading.State = MyLoading.LoadingState.Loading; + } + + private void Button2_OnClick(object? sender, RoutedEventArgs e) + { + this.TestLoading.State = MyLoading.LoadingState.Error; + } + + private async void Search_Java_Button(object? sender, RoutedEventArgs e) + { + try + { + var javas = await Java.SearchJava(); + Console.WriteLine($"找到 {javas.Count()} 个Java环境:"); + + foreach (var java in javas) + { + try + { + Console.WriteLine("----------------------"); + Console.WriteLine($"路径: {java.DirectoryPath}"); + var version = java.Version; + Console.WriteLine($"版本: Java {version}"); + Console.WriteLine($"位数: {(java.Is64Bit ? "64位" : "32位")}"); + Console.WriteLine($"类型: {(java.IsJre ? "JRE" : "JDK")}"); + Console.WriteLine($"可用: {java.Compability}"); + } + catch (Exception ex) + { + Console.WriteLine($"处理Java信息时出错: {ex.Message}"); + } + } + } + catch (Exception ex) + { + Console.WriteLine($"搜索失败: {ex.Message}"); + } + } +} \ No newline at end of file diff --git a/PCL2.Neo/Views/HomeLeftView.axaml b/PCL2.Neo/Views/HomeLeftView.axaml deleted file mode 100644 index f9bd20fb..00000000 --- a/PCL2.Neo/Views/HomeLeftView.axaml +++ /dev/null @@ -1,12 +0,0 @@ - - Welcome to Avalonia!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - - diff --git a/PCL2.Neo/Views/HomeLeftView.axaml.cs b/PCL2.Neo/Views/HomeLeftView.axaml.cs deleted file mode 100644 index 16ced31a..00000000 --- a/PCL2.Neo/Views/HomeLeftView.axaml.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Avalonia; -using Avalonia.Controls; -using Avalonia.Markup.Xaml; - -namespace PCL2.Neo.Views -{ - public partial class HomeLeftView : UserControl - { - public HomeLeftView() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/PCL2.Neo/Views/HomeView.axaml b/PCL2.Neo/Views/HomeView.axaml index cde008df..ba939041 100644 --- a/PCL2.Neo/Views/HomeView.axaml +++ b/PCL2.Neo/Views/HomeView.axaml @@ -2,50 +2,12 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:pc="using:PCL2.Neo.Controls" xmlns:vm="using:PCL2.Neo.ViewModels" - mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" + xmlns:home="clr-namespace:PCL2.Neo.ViewModels.Home" + mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="250" x:Class="PCL2.Neo.Views.HomeView" - x:DataType="vm:HomeViewModel"> - - - - - - - - - - - - - - - - - - - - - + x:DataType="home:HomeSubViewModel" + Width="250"> + Welcome to Avalonia!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + diff --git a/PCL2.Neo/Views/HomeView.axaml.cs b/PCL2.Neo/Views/HomeView.axaml.cs index 798e8ad4..d5c929cf 100644 --- a/PCL2.Neo/Views/HomeView.axaml.cs +++ b/PCL2.Neo/Views/HomeView.axaml.cs @@ -1,59 +1,14 @@ using Avalonia; using Avalonia.Controls; -using Avalonia.Interactivity; using Avalonia.Markup.Xaml; -using PCL2.Neo.Controls; -using PCL2.Neo.Models.Minecraft.Java; -using System; -using System.Linq; -namespace PCL2.Neo.Views; - -public partial class HomeView : UserControl +namespace PCL2.Neo.Views { - public HomeView() - { - InitializeComponent(); - } - - private void Button_OnClick(object? sender, RoutedEventArgs e) - { - this.TestLoading.State = MyLoading.LoadingState.Loading; - } - - private void Button2_OnClick(object? sender, RoutedEventArgs e) + public partial class HomeView : UserControl { - this.TestLoading.State = MyLoading.LoadingState.Error; - } - - private async void Search_Java_Button(object? sender, RoutedEventArgs e) - { - try - { - var javas = await Java.SearchJava(); - Console.WriteLine($"找到 {javas.Count()} 个Java环境:"); - - foreach (var java in javas) - { - try - { - Console.WriteLine("----------------------"); - Console.WriteLine($"路径: {java.DirectoryPath}"); - var version = java.Version; - Console.WriteLine($"版本: Java {version}"); - Console.WriteLine($"位数: {(java.Is64Bit ? "64位" : "32位")}"); - Console.WriteLine($"类型: {(java.IsJre ? "JRE" : "JDK")}"); - Console.WriteLine($"可用: {java.Compability}"); - } - catch (Exception ex) - { - Console.WriteLine($"处理Java信息时出错: {ex.Message}"); - } - } - } - catch (Exception ex) + public HomeView() { - Console.WriteLine($"搜索失败: {ex.Message}"); + InitializeComponent(); } } } \ No newline at end of file diff --git a/PCL2.Neo/Views/MainWindow.axaml b/PCL2.Neo/Views/MainWindow.axaml index 4f6f7f0f..fd09e55b 100644 --- a/PCL2.Neo/Views/MainWindow.axaml +++ b/PCL2.Neo/Views/MainWindow.axaml @@ -154,7 +154,7 @@ Orientation="Horizontal" VerticalAlignment="Center"> - + BoxShadow="0 0 15 0 DarkGray" /> - - - - + ZIndex="2" /> - + Content="{Binding CurrentSubViewModel}" /> Date: Sun, 4 May 2025 22:46:08 +0800 Subject: [PATCH 4/4] chore: fix build error --- PCL2.Neo/ViewModels/MainWindowViewModel.cs | 2 +- PCL2.Neo/Views/MainWindow.axaml | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/PCL2.Neo/ViewModels/MainWindowViewModel.cs b/PCL2.Neo/ViewModels/MainWindowViewModel.cs index f82e33a1..f252a6d8 100644 --- a/PCL2.Neo/ViewModels/MainWindowViewModel.cs +++ b/PCL2.Neo/ViewModels/MainWindowViewModel.cs @@ -81,7 +81,7 @@ public void Minimize() _window.WindowState = WindowState.Minimized; } - public void ShowMessageBox((MessageBoxParam, TaskCompletionSource) messageBoxParam) + public void ShowMessageBox(IMessageBox messageBox) { } diff --git a/PCL2.Neo/Views/MainWindow.axaml b/PCL2.Neo/Views/MainWindow.axaml index f6019fdb..7bfaa599 100644 --- a/PCL2.Neo/Views/MainWindow.axaml +++ b/PCL2.Neo/Views/MainWindow.axaml @@ -19,7 +19,6 @@ xmlns:pc="using:PCL2.Neo.Controls" xmlns:vm="using:PCL2.Neo.ViewModels" xmlns:local="using:PCL2.Neo" - xmlns:vm="clr-namespace:PCL2.Neo.ViewModels" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">