Avalonia Boilerplate
This commit is contained in:
parent
a6d5a3eb72
commit
0d32e6a5c3
14 changed files with 117 additions and 23 deletions
|
|
@ -1,6 +1,5 @@
|
|||
<Application xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:InkForge.Common"
|
||||
x:Class="InkForge.Common.App"
|
||||
RequestedThemeVariant="Default">
|
||||
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
|
||||
|
|
|
|||
|
|
@ -3,6 +3,10 @@ using Avalonia.Controls;
|
|||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
using InkForge.Common.ViewModels;
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
using ReactiveUI;
|
||||
|
||||
namespace InkForge.Common;
|
||||
|
|
@ -20,21 +24,15 @@ public partial class App : Application
|
|||
|
||||
public override void OnFrameworkInitializationCompleted()
|
||||
{
|
||||
// var viewModel = Services.Activate<MainViewModel>();
|
||||
// var view = ViewLocator.Current.ResolveView(viewModel);
|
||||
// switch (ApplicationLifetime)
|
||||
// {
|
||||
// case IClassicDesktopStyleApplicationLifetime desktop:
|
||||
// desktop.MainWindow = view as Window;
|
||||
// break;
|
||||
|
||||
// case ISingleViewApplicationLifetime singleView:
|
||||
// singleView.MainView = view as Control;
|
||||
// break;
|
||||
|
||||
// default:
|
||||
// throw new NotSupportedException();
|
||||
// }
|
||||
var viewModel = ActivatorUtilities.GetServiceOrCreateInstance<AppViewModel>(ServiceProvider);
|
||||
var view = ViewLocator.Current.ResolveView(viewModel)!;
|
||||
view.ViewModel = viewModel;
|
||||
_ = ApplicationLifetime switch
|
||||
{
|
||||
IClassicDesktopStyleApplicationLifetime desktop => desktop.MainWindow = view as Window,
|
||||
ISingleViewApplicationLifetime singleView => singleView.MainView = view as Control,
|
||||
_ => throw new NotSupportedException(),
|
||||
};
|
||||
|
||||
base.OnFrameworkInitializationCompleted();
|
||||
}
|
||||
|
|
|
|||
5
app/InkForge.Common/Controllers/WorkspaceController.cs
Normal file
5
app/InkForge.Common/Controllers/WorkspaceController.cs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
namespace InkForge.Common.Controllers;
|
||||
|
||||
public class WorkspaceController
|
||||
{
|
||||
}
|
||||
15
app/InkForge.Common/Data/NoteDbContextFactory.cs
Normal file
15
app/InkForge.Common/Data/NoteDbContextFactory.cs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
using InkForge.Data;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace InkForge.Common.Data;
|
||||
|
||||
public class NoteDbContextFactory : IDbContextFactory<NoteDbContext>
|
||||
{
|
||||
|
||||
public NoteDbContext CreateDbContext()
|
||||
{
|
||||
return new NoteDbContext(null);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -8,6 +8,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Avalonia.Fonts.Inter" />
|
||||
<PackageReference Include="Avalonia.ReactiveUI" />
|
||||
<PackageReference Include="Avalonia.Themes.Fluent" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
using InkForge.Common.Controllers;
|
||||
using InkForge.Common.Data;
|
||||
using InkForge.Data;
|
||||
|
||||
namespace Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
public static class InkForgeServiceCollections
|
||||
{
|
||||
public static IServiceCollection AddInkForge(this IServiceCollection services)
|
||||
{
|
||||
services.AddHttpClient();
|
||||
|
||||
services.AddDbContextFactory<NoteDbContext, NoteDbContextFactory>();
|
||||
|
||||
services.AddSingleton<WorkspaceController>();
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
7
app/InkForge.Common/Properties/ConfigContext.cs
Normal file
7
app/InkForge.Common/Properties/ConfigContext.cs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace InkForge.Common.Properties;
|
||||
|
||||
[JsonSerializable(typeof(IDictionary<string, object>))]
|
||||
[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Metadata)]
|
||||
public partial class ConfigContext : JsonSerializerContext;
|
||||
20
app/InkForge.Common/ViewModels/AppViewModel.cs
Normal file
20
app/InkForge.Common/ViewModels/AppViewModel.cs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
using InkForge.Common.Controllers;
|
||||
|
||||
using ReactiveUI;
|
||||
|
||||
namespace InkForge.Common.ViewModels;
|
||||
|
||||
public class AppViewModel : ReactiveObject
|
||||
{
|
||||
private object _view;
|
||||
|
||||
public object View
|
||||
{
|
||||
get => _view;
|
||||
set => this.RaiseAndSetIfChanged(ref _view, value);
|
||||
}
|
||||
|
||||
public AppViewModel(WorkspaceController workspace)
|
||||
{
|
||||
}
|
||||
}
|
||||
8
app/InkForge.Common/ViewModels/LandingViewModel.cs
Normal file
8
app/InkForge.Common/ViewModels/LandingViewModel.cs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
using ReactiveUI;
|
||||
|
||||
namespace InkForge.Common.ViewModels;
|
||||
|
||||
public class LandingViewModel : ReactiveObject
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -17,4 +17,4 @@
|
|||
<ProjectReference Include="..\InkForge.Common\InkForge.Common.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
</Project>
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
using Avalonia;
|
||||
using Avalonia;
|
||||
using Avalonia.ReactiveUI;
|
||||
using Avalonia.Threading;
|
||||
|
||||
using InkForge.Common;
|
||||
using InkForge.Data;
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
|
|
@ -23,6 +24,7 @@ static class Program
|
|||
=> AppBuilder.Configure<App>()
|
||||
.UsePlatformDetect()
|
||||
.UseReactiveUI()
|
||||
.WithInterFont()
|
||||
.LogToTrace();
|
||||
|
||||
private static void ConfigureServices(IServiceCollection services)
|
||||
|
|
@ -32,11 +34,7 @@ static class Program
|
|||
mutableResolver.InitializeSplat();
|
||||
mutableResolver.InitializeReactiveUI();
|
||||
|
||||
services.AddHttpClient();
|
||||
|
||||
// services.UseFactories();
|
||||
// services.AddViewModelFactory();
|
||||
// services.AddTransient<IViewFor<MainViewModel>, MainWindow>();
|
||||
services.AddInkForge();
|
||||
}
|
||||
|
||||
private static void OnSetup(this IServiceCollection services, AppBuilder appBuilder)
|
||||
|
|
|
|||
9
app/InkForge.Desktop/Views/MainWindow.axaml
Normal file
9
app/InkForge.Desktop/Views/MainWindow.axaml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<Window xmlns="https://github.com/avaloniaui"
|
||||
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"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="InkForge.Desktop.Views.MainWindow"
|
||||
Title="InkForge">
|
||||
|
||||
</Window>
|
||||
13
app/InkForge.Desktop/Views/MainWindow.axaml.cs
Normal file
13
app/InkForge.Desktop/Views/MainWindow.axaml.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
using Avalonia.ReactiveUI;
|
||||
|
||||
using InkForge.Common.ViewModels;
|
||||
|
||||
namespace InkForge.Desktop.Views;
|
||||
|
||||
public partial class MainWindow : ReactiveWindow<AppViewModel>
|
||||
{
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue