From 088a09bbfd9bf8ebcdf3dd193cef688f37efe3c5 Mon Sep 17 00:00:00 2001 From: Weicao-CatilGrass <1992414357@qq.com> Date: Thu, 18 Dec 2025 01:12:54 +0800 Subject: First commit --- .gitignore | 5 +++ DesktopClient.sln | 16 ++++++++++ JVDesktop/App.axaml | 15 +++++++++ JVDesktop/App.axaml.cs | 47 ++++++++++++++++++++++++++++ JVDesktop/Assets/avalonia-logo.ico | Bin 0 -> 175875 bytes JVDesktop/JVDesktop.csproj | 28 +++++++++++++++++ JVDesktop/Program.cs | 21 +++++++++++++ JVDesktop/ViewLocator.cs | 31 ++++++++++++++++++ JVDesktop/ViewModels/MainWindowViewModel.cs | 6 ++++ JVDesktop/ViewModels/ViewModelBase.cs | 7 +++++ JVDesktop/Views/MainWindow.axaml | 20 ++++++++++++ JVDesktop/Views/MainWindow.axaml.cs | 11 +++++++ JVDesktop/app.manifest | 18 +++++++++++ 13 files changed, 225 insertions(+) create mode 100644 .gitignore create mode 100644 DesktopClient.sln create mode 100644 JVDesktop/App.axaml create mode 100644 JVDesktop/App.axaml.cs create mode 100644 JVDesktop/Assets/avalonia-logo.ico create mode 100644 JVDesktop/JVDesktop.csproj create mode 100644 JVDesktop/Program.cs create mode 100644 JVDesktop/ViewLocator.cs create mode 100644 JVDesktop/ViewModels/MainWindowViewModel.cs create mode 100644 JVDesktop/ViewModels/ViewModelBase.cs create mode 100644 JVDesktop/Views/MainWindow.axaml create mode 100644 JVDesktop/Views/MainWindow.axaml.cs create mode 100644 JVDesktop/app.manifest diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0bcaf7c --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.idea/ +**/bin +**/obj +bin/** +obj/** diff --git a/DesktopClient.sln b/DesktopClient.sln new file mode 100644 index 0000000..97fd4d3 --- /dev/null +++ b/DesktopClient.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JVDesktop", "JVDesktop\JVDesktop.csproj", "{2EF80E70-ACDD-431B-A773-9CA2EA00A233}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2EF80E70-ACDD-431B-A773-9CA2EA00A233}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2EF80E70-ACDD-431B-A773-9CA2EA00A233}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2EF80E70-ACDD-431B-A773-9CA2EA00A233}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2EF80E70-ACDD-431B-A773-9CA2EA00A233}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/JVDesktop/App.axaml b/JVDesktop/App.axaml new file mode 100644 index 0000000..24e82f2 --- /dev/null +++ b/JVDesktop/App.axaml @@ -0,0 +1,15 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/JVDesktop/App.axaml.cs b/JVDesktop/App.axaml.cs new file mode 100644 index 0000000..b1bc4c0 --- /dev/null +++ b/JVDesktop/App.axaml.cs @@ -0,0 +1,47 @@ +using Avalonia; +using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Data.Core; +using Avalonia.Data.Core.Plugins; +using System.Linq; +using Avalonia.Markup.Xaml; +using JVDesktop.ViewModels; +using JVDesktop.Views; + +namespace JVDesktop; + +public partial class App : Application +{ + public override void Initialize() + { + AvaloniaXamlLoader.Load(this); + } + + public override void OnFrameworkInitializationCompleted() + { + 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 + { + DataContext = new MainWindowViewModel(), + }; + } + + base.OnFrameworkInitializationCompleted(); + } + + private void DisableAvaloniaDataAnnotationValidation() + { + // Get an array of plugins to remove + var dataValidationPluginsToRemove = + BindingPlugins.DataValidators.OfType().ToArray(); + + // remove each entry found + foreach (var plugin in dataValidationPluginsToRemove) + { + BindingPlugins.DataValidators.Remove(plugin); + } + } +} \ No newline at end of file diff --git a/JVDesktop/Assets/avalonia-logo.ico b/JVDesktop/Assets/avalonia-logo.ico new file mode 100644 index 0000000..f7da8bb Binary files /dev/null and b/JVDesktop/Assets/avalonia-logo.ico differ diff --git a/JVDesktop/JVDesktop.csproj b/JVDesktop/JVDesktop.csproj new file mode 100644 index 0000000..5ba2c97 --- /dev/null +++ b/JVDesktop/JVDesktop.csproj @@ -0,0 +1,28 @@ + + + WinExe + net9.0 + enable + true + app.manifest + true + + + + + + + + + + + + + + + None + All + + + + diff --git a/JVDesktop/Program.cs b/JVDesktop/Program.cs new file mode 100644 index 0000000..8d39a63 --- /dev/null +++ b/JVDesktop/Program.cs @@ -0,0 +1,21 @@ +using Avalonia; +using System; + +namespace JVDesktop; + +sealed class Program +{ + // Initialization code. Don't use any Avalonia, third-party APIs or any + // SynchronizationContext-reliant code before AppMain is called: things aren't initialized + // yet and stuff might break. + [STAThread] + public static void Main(string[] args) => BuildAvaloniaApp() + .StartWithClassicDesktopLifetime(args); + + // Avalonia configuration, don't remove; also used by visual designer. + public static AppBuilder BuildAvaloniaApp() + => AppBuilder.Configure() + .UsePlatformDetect() + .WithInterFont() + .LogToTrace(); +} diff --git a/JVDesktop/ViewLocator.cs b/JVDesktop/ViewLocator.cs new file mode 100644 index 0000000..f289d15 --- /dev/null +++ b/JVDesktop/ViewLocator.cs @@ -0,0 +1,31 @@ +using System; +using Avalonia.Controls; +using Avalonia.Controls.Templates; +using JVDesktop.ViewModels; + +namespace JVDesktop; + +public class ViewLocator : IDataTemplate +{ + + 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) + { + return (Control)Activator.CreateInstance(type)!; + } + + return new TextBlock { Text = "Not Found: " + name }; + } + + public bool Match(object? data) + { + return data is ViewModelBase; + } +} diff --git a/JVDesktop/ViewModels/MainWindowViewModel.cs b/JVDesktop/ViewModels/MainWindowViewModel.cs new file mode 100644 index 0000000..0ca52c8 --- /dev/null +++ b/JVDesktop/ViewModels/MainWindowViewModel.cs @@ -0,0 +1,6 @@ +namespace JVDesktop.ViewModels; + +public partial class MainWindowViewModel : ViewModelBase +{ + public string Greeting { get; } = "Welcome to Avalonia!"; +} diff --git a/JVDesktop/ViewModels/ViewModelBase.cs b/JVDesktop/ViewModels/ViewModelBase.cs new file mode 100644 index 0000000..bd3dbd8 --- /dev/null +++ b/JVDesktop/ViewModels/ViewModelBase.cs @@ -0,0 +1,7 @@ +using CommunityToolkit.Mvvm.ComponentModel; + +namespace JVDesktop.ViewModels; + +public class ViewModelBase : ObservableObject +{ +} diff --git a/JVDesktop/Views/MainWindow.axaml b/JVDesktop/Views/MainWindow.axaml new file mode 100644 index 0000000..9fb406d --- /dev/null +++ b/JVDesktop/Views/MainWindow.axaml @@ -0,0 +1,20 @@ + + + + + + + + + + diff --git a/JVDesktop/Views/MainWindow.axaml.cs b/JVDesktop/Views/MainWindow.axaml.cs new file mode 100644 index 0000000..37f530e --- /dev/null +++ b/JVDesktop/Views/MainWindow.axaml.cs @@ -0,0 +1,11 @@ +using Avalonia.Controls; + +namespace JVDesktop.Views; + +public partial class MainWindow : Window +{ + public MainWindow() + { + InitializeComponent(); + } +} \ No newline at end of file diff --git a/JVDesktop/app.manifest b/JVDesktop/app.manifest new file mode 100644 index 0000000..85ade99 --- /dev/null +++ b/JVDesktop/app.manifest @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + -- cgit