From ad0943f88ba9f5ed6eae198ecb4835c0f44701de Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Wed, 17 Jun 2026 21:33:40 +0800 Subject: chore: initialize project structure and add core modules --- rola-desktop/App.axaml | 15 ++++++++ rola-desktop/App.axaml.cs | 47 +++++++++++++++++++++++++ rola-desktop/Assets/avalonia-logo.ico | Bin 0 -> 175875 bytes rola-desktop/Program.cs | 21 +++++++++++ rola-desktop/ViewLocator.cs | 31 ++++++++++++++++ rola-desktop/ViewModels/MainWindowViewModel.cs | 6 ++++ rola-desktop/ViewModels/ViewModelBase.cs | 7 ++++ rola-desktop/Views/MainWindow.axaml | 20 +++++++++++ rola-desktop/Views/MainWindow.axaml.cs | 11 ++++++ rola-desktop/app.manifest | 18 ++++++++++ rola-desktop/rola-desktop.csproj | 32 +++++++++++++++++ 11 files changed, 208 insertions(+) create mode 100644 rola-desktop/App.axaml create mode 100644 rola-desktop/App.axaml.cs create mode 100644 rola-desktop/Assets/avalonia-logo.ico create mode 100644 rola-desktop/Program.cs create mode 100644 rola-desktop/ViewLocator.cs create mode 100644 rola-desktop/ViewModels/MainWindowViewModel.cs create mode 100644 rola-desktop/ViewModels/ViewModelBase.cs create mode 100644 rola-desktop/Views/MainWindow.axaml create mode 100644 rola-desktop/Views/MainWindow.axaml.cs create mode 100644 rola-desktop/app.manifest create mode 100644 rola-desktop/rola-desktop.csproj (limited to 'rola-desktop') diff --git a/rola-desktop/App.axaml b/rola-desktop/App.axaml new file mode 100644 index 0000000..bd879fe --- /dev/null +++ b/rola-desktop/App.axaml @@ -0,0 +1,15 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/rola-desktop/App.axaml.cs b/rola-desktop/App.axaml.cs new file mode 100644 index 0000000..6b665bc --- /dev/null +++ b/rola-desktop/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 rola_desktop.ViewModels; +using rola_desktop.Views; + +namespace rola_desktop; + +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/rola-desktop/Assets/avalonia-logo.ico b/rola-desktop/Assets/avalonia-logo.ico new file mode 100644 index 0000000..f7da8bb Binary files /dev/null and b/rola-desktop/Assets/avalonia-logo.ico differ diff --git a/rola-desktop/Program.cs b/rola-desktop/Program.cs new file mode 100644 index 0000000..30e9ca6 --- /dev/null +++ b/rola-desktop/Program.cs @@ -0,0 +1,21 @@ +using Avalonia; +using System; + +namespace rola_desktop; + +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/rola-desktop/ViewLocator.cs b/rola-desktop/ViewLocator.cs new file mode 100644 index 0000000..eec4713 --- /dev/null +++ b/rola-desktop/ViewLocator.cs @@ -0,0 +1,31 @@ +using System; +using Avalonia.Controls; +using Avalonia.Controls.Templates; +using rola_desktop.ViewModels; + +namespace rola_desktop; + +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/rola-desktop/ViewModels/MainWindowViewModel.cs b/rola-desktop/ViewModels/MainWindowViewModel.cs new file mode 100644 index 0000000..2db588d --- /dev/null +++ b/rola-desktop/ViewModels/MainWindowViewModel.cs @@ -0,0 +1,6 @@ +namespace rola_desktop.ViewModels; + +public partial class MainWindowViewModel : ViewModelBase +{ + public string Greeting { get; } = "Welcome to Avalonia!"; +} diff --git a/rola-desktop/ViewModels/ViewModelBase.cs b/rola-desktop/ViewModels/ViewModelBase.cs new file mode 100644 index 0000000..f0aa7f1 --- /dev/null +++ b/rola-desktop/ViewModels/ViewModelBase.cs @@ -0,0 +1,7 @@ +using CommunityToolkit.Mvvm.ComponentModel; + +namespace rola_desktop.ViewModels; + +public class ViewModelBase : ObservableObject +{ +} diff --git a/rola-desktop/Views/MainWindow.axaml b/rola-desktop/Views/MainWindow.axaml new file mode 100644 index 0000000..6ed88af --- /dev/null +++ b/rola-desktop/Views/MainWindow.axaml @@ -0,0 +1,20 @@ + + + + + + + + + + diff --git a/rola-desktop/Views/MainWindow.axaml.cs b/rola-desktop/Views/MainWindow.axaml.cs new file mode 100644 index 0000000..14f9599 --- /dev/null +++ b/rola-desktop/Views/MainWindow.axaml.cs @@ -0,0 +1,11 @@ +using Avalonia.Controls; + +namespace rola_desktop.Views; + +public partial class MainWindow : Window +{ + public MainWindow() + { + InitializeComponent(); + } +} \ No newline at end of file diff --git a/rola-desktop/app.manifest b/rola-desktop/app.manifest new file mode 100644 index 0000000..6454463 --- /dev/null +++ b/rola-desktop/app.manifest @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + diff --git a/rola-desktop/rola-desktop.csproj b/rola-desktop/rola-desktop.csproj new file mode 100644 index 0000000..5d6e1f8 --- /dev/null +++ b/rola-desktop/rola-desktop.csproj @@ -0,0 +1,32 @@ + + + WinExe + net9.0 + enable + true + app.manifest + true + + + + + + + + + + + + + + None + All + + + + -- cgit