summaryrefslogtreecommitdiff
path: root/rola-desktop
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-06-17 21:33:40 +0800
committer魏曹先生 <1992414357@qq.com>2026-06-17 21:57:13 +0800
commitad0943f88ba9f5ed6eae198ecb4835c0f44701de (patch)
tree6a8eb1fee42e7ee173e74788dafeb27c52429683 /rola-desktop
chore: initialize project structure and add core modules
Diffstat (limited to 'rola-desktop')
-rw-r--r--rola-desktop/App.axaml15
-rw-r--r--rola-desktop/App.axaml.cs47
-rw-r--r--rola-desktop/Assets/avalonia-logo.icobin0 -> 175875 bytes
-rw-r--r--rola-desktop/Program.cs21
-rw-r--r--rola-desktop/ViewLocator.cs31
-rw-r--r--rola-desktop/ViewModels/MainWindowViewModel.cs6
-rw-r--r--rola-desktop/ViewModels/ViewModelBase.cs7
-rw-r--r--rola-desktop/Views/MainWindow.axaml20
-rw-r--r--rola-desktop/Views/MainWindow.axaml.cs11
-rw-r--r--rola-desktop/app.manifest18
-rw-r--r--rola-desktop/rola-desktop.csproj32
11 files changed, 208 insertions, 0 deletions
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 @@
+<Application xmlns="https://github.com/avaloniaui"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ x:Class="rola_desktop.App"
+ xmlns:local="using:rola_desktop"
+ RequestedThemeVariant="Default">
+ <!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
+
+ <Application.DataTemplates>
+ <local:ViewLocator/>
+ </Application.DataTemplates>
+
+ <Application.Styles>
+ <FluentTheme />
+ </Application.Styles>
+</Application> \ 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<DataAnnotationsValidationPlugin>().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
--- /dev/null
+++ b/rola-desktop/Assets/avalonia-logo.ico
Binary files 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<App>()
+ .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 @@
+<Window xmlns="https://github.com/avaloniaui"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:vm="using:rola_desktop.ViewModels"
+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
+ x:Class="rola_desktop.Views.MainWindow"
+ x:DataType="vm:MainWindowViewModel"
+ Icon="/Assets/avalonia-logo.ico"
+ Title="rola_desktop">
+
+ <Design.DataContext>
+ <!-- This only sets the DataContext for the previewer in an IDE,
+ to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
+ <vm:MainWindowViewModel/>
+ </Design.DataContext>
+
+ <TextBlock Text="{Binding Greeting}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
+
+</Window>
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 @@
+<?xml version="1.0" encoding="utf-8"?>
+<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
+ <!-- This manifest is used on Windows only.
+ Don't remove it as it might cause problems with window transparency and embedded controls.
+ For more details visit https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests -->
+ <assemblyIdentity version="1.0.0.0" name="rola_desktop.Desktop"/>
+
+ <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
+ <application>
+ <!-- A list of the Windows versions that this application has been tested on
+ and is designed to work with. Uncomment the appropriate elements
+ and Windows will automatically select the most compatible environment. -->
+
+ <!-- Windows 10 -->
+ <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
+ </application>
+ </compatibility>
+</assembly>
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 @@
+<Project Sdk="Microsoft.NET.Sdk">
+ <PropertyGroup>
+ <OutputType>WinExe</OutputType>
+ <TargetFramework>net9.0</TargetFramework>
+ <Nullable>enable</Nullable>
+ <BuiltInComInteropSupport>true</BuiltInComInteropSupport>
+ <ApplicationManifest>app.manifest</ApplicationManifest>
+ <AvaloniaUseCompiledBindingsByDefault
+ >true</AvaloniaUseCompiledBindingsByDefault>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <Folder Include="Models\" />
+ <AvaloniaResource Include="Assets\**" />
+ </ItemGroup>
+
+ <ItemGroup>
+ <PackageReference Include="Avalonia" Version="11.3.2" />
+ <PackageReference Include="Avalonia.Desktop" Version="11.3.2" />
+ <PackageReference Include="Avalonia.Themes.Fluent" Version="11.3.2" />
+ <PackageReference Include="Avalonia.Fonts.Inter" Version="11.3.2" />
+ <PackageReference Include="Avalonia.Diagnostics" Version="11.3.2">
+ <IncludeAssets
+ Condition="'$(Configuration)' != 'Debug'"
+ >None</IncludeAssets>
+ <PrivateAssets
+ Condition="'$(Configuration)' != 'Debug'"
+ >All</PrivateAssets>
+ </PackageReference>
+ <PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
+ </ItemGroup>
+</Project>