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
|
||||
{
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue