summaryrefslogtreecommitdiff
path: root/JVDesktop
diff options
context:
space:
mode:
authorWeicao-CatilGrass <1992414357@qq.com>2025-12-18 01:12:54 +0800
committerWeicao-CatilGrass <1992414357@qq.com>2025-12-18 01:12:54 +0800
commit088a09bbfd9bf8ebcdf3dd193cef688f37efe3c5 (patch)
tree2f3f4f46456ec3d54a936d028fac207a2d851778 /JVDesktop
parent764c177237dfeebfd53895a68f42145f892e9eda (diff)
First commit
Diffstat (limited to 'JVDesktop')
-rw-r--r--JVDesktop/App.axaml15
-rw-r--r--JVDesktop/App.axaml.cs47
-rw-r--r--JVDesktop/Assets/avalonia-logo.icobin0 -> 175875 bytes
-rw-r--r--JVDesktop/JVDesktop.csproj28
-rw-r--r--JVDesktop/Program.cs21
-rw-r--r--JVDesktop/ViewLocator.cs31
-rw-r--r--JVDesktop/ViewModels/MainWindowViewModel.cs6
-rw-r--r--JVDesktop/ViewModels/ViewModelBase.cs7
-rw-r--r--JVDesktop/Views/MainWindow.axaml20
-rw-r--r--JVDesktop/Views/MainWindow.axaml.cs11
-rw-r--r--JVDesktop/app.manifest18
11 files changed, 204 insertions, 0 deletions
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 @@
+<Application xmlns="https://github.com/avaloniaui"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ x:Class="JVDesktop.App"
+ xmlns:local="using:JVDesktop"
+ 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/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<DataAnnotationsValidationPlugin>().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
--- /dev/null
+++ b/JVDesktop/Assets/avalonia-logo.ico
Binary files 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 @@
+<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.4"/>
+ <PackageReference Include="Avalonia.Desktop" Version="11.3.4"/>
+ <PackageReference Include="Avalonia.Themes.Fluent" Version="11.3.4"/>
+ <PackageReference Include="Avalonia.Fonts.Inter" Version="11.3.4"/>
+ <!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
+ <PackageReference Include="Avalonia.Diagnostics" Version="11.3.4">
+ <IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
+ <PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
+ </PackageReference>
+ <PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1"/>
+ </ItemGroup>
+</Project>
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<App>()
+ .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 @@
+<Window xmlns="https://github.com/avaloniaui"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:vm="using:JVDesktop.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="JVDesktop.Views.MainWindow"
+ x:DataType="vm:MainWindowViewModel"
+ Icon="/Assets/avalonia-logo.ico"
+ Title="JVDesktop">
+
+ <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/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 @@
+<?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="JVDesktop.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>