Skip to content

Commit ae93249

Browse files
committed
Removed avalonia
1 parent 0d6579e commit ae93249

17 files changed

Lines changed: 305 additions & 6 deletions

CutCode.sln

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ VisualStudioVersion = 16.0.31515.178
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CutCode", "CutCode\CutCode.csproj", "{05099602-B5CB-4056-A265-035AD8982699}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CutCode.MultiPlatform", "CutCode.MultiPlatform\CutCode.MultiPlatform.csproj", "{83FE2EDD-C55D-41F1-9664-D2DFECF1BC25}"
9-
EndProject
108
Global
119
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1210
Debug|Any CPU = Debug|Any CPU
@@ -17,10 +15,6 @@ Global
1715
{05099602-B5CB-4056-A265-035AD8982699}.Debug|Any CPU.Build.0 = Debug|Any CPU
1816
{05099602-B5CB-4056-A265-035AD8982699}.Release|Any CPU.ActiveCfg = Release|Any CPU
1917
{05099602-B5CB-4056-A265-035AD8982699}.Release|Any CPU.Build.0 = Release|Any CPU
20-
{83FE2EDD-C55D-41F1-9664-D2DFECF1BC25}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21-
{83FE2EDD-C55D-41F1-9664-D2DFECF1BC25}.Debug|Any CPU.Build.0 = Debug|Any CPU
22-
{83FE2EDD-C55D-41F1-9664-D2DFECF1BC25}.Release|Any CPU.ActiveCfg = Release|Any CPU
23-
{83FE2EDD-C55D-41F1-9664-D2DFECF1BC25}.Release|Any CPU.Build.0 = Release|Any CPU
2418
EndGlobalSection
2519
GlobalSection(SolutionProperties) = preSolution
2620
HideSolutionNode = FALSE

Todo/App.axaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Application xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:local="using:Todo"
4+
x:Class="Todo.App">
5+
<Application.DataTemplates>
6+
<local:ViewLocator/>
7+
</Application.DataTemplates>
8+
9+
<Application.Styles>
10+
<FluentTheme Mode="Light"/>
11+
</Application.Styles>
12+
</Application>

Todo/App.axaml.cs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using Avalonia;
2+
using Avalonia.Controls;
3+
using Avalonia.Controls.ApplicationLifetimes;
4+
using Avalonia.Markup.Xaml;
5+
using Live.Avalonia;
6+
using ReactiveUI;
7+
using System;
8+
using System.Diagnostics;
9+
using System.Reactive;
10+
using Todo.Services;
11+
using Todo.ViewModels;
12+
using Todo.Views;
13+
14+
namespace Todo
15+
{
16+
public class App : Application, ILiveView
17+
{
18+
public override void Initialize()
19+
{
20+
AvaloniaXamlLoader.Load(this);
21+
}
22+
23+
public override void OnFrameworkInitializationCompleted()
24+
{
25+
if (Debugger.IsAttached || IsProduction())
26+
{
27+
// Debugging requires pdb loading etc, so we disable live reloading
28+
// during a test run with an attached debugger.
29+
var window = new Window();
30+
window.Content = CreateView(window);
31+
window.Show();
32+
}
33+
else
34+
{
35+
// Here, we create a new LiveViewHost, located in the 'Live.Avalonia'
36+
// namespace, and pass an ILiveView implementation to it. The ILiveView
37+
// implementation should have a parameterless constructor! Next, we
38+
// start listening for any changes in the source files. And then, we
39+
// show the LiveViewHost window. Simple enough, huh?
40+
var window = new LiveViewHost(this, Console.WriteLine);
41+
window.StartWatchingSourceFilesForHotReloading();
42+
window.Show();
43+
}
44+
45+
// Here we subscribe to ReactiveUI default exception handler to avoid app
46+
// termination in case if we do something wrong in our view models. See:
47+
// https://www.reactiveui.net/docs/handbook/default-exception-handler/
48+
//
49+
// In case if you are using another MV* framework, please refer to its
50+
// documentation explaining global exception handling.
51+
RxApp.DefaultExceptionHandler = Observer.Create<Exception>(Console.WriteLine);
52+
base.OnFrameworkInitializationCompleted();
53+
}
54+
55+
public object CreateView(Window window)
56+
{
57+
var db = new Database();
58+
window.DataContext ??= new MainWindowViewModel(db);
59+
return new MainWindow();
60+
61+
}
62+
63+
private static bool IsProduction()
64+
{
65+
#if DEBUG
66+
return false;
67+
#else
68+
return true;
69+
#endif
70+
}
71+
}
72+
}

Todo/Assets/avalonia-logo.ico

172 KB
Binary file not shown.

Todo/Models/TodoItem.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Todo.Models
8+
{
9+
public class TodoItem
10+
{
11+
public string Description { get; set; }
12+
public bool IsChecked { get; set; }
13+
}
14+
}

Todo/Program.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Avalonia;
2+
using Avalonia.Controls.ApplicationLifetimes;
3+
using Avalonia.ReactiveUI;
4+
using System;
5+
6+
namespace Todo
7+
{
8+
class Program
9+
{
10+
// Initialization code. Don't use any Avalonia, third-party APIs or any
11+
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
12+
// yet and stuff might break.
13+
public static void Main(string[] args) => BuildAvaloniaApp()
14+
.StartWithClassicDesktopLifetime(args);
15+
16+
// Avalonia configuration, don't remove; also used by visual designer.
17+
public static AppBuilder BuildAvaloniaApp()
18+
=> AppBuilder.Configure<App>()
19+
.UsePlatformDetect()
20+
.LogToTrace()
21+
.UseReactiveUI();
22+
}
23+
}

Todo/Services/Database.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System.Collections.Generic;
2+
using Todo.Models;
3+
4+
namespace Todo.Services
5+
{
6+
public class Database
7+
{
8+
public IEnumerable<TodoItem> GetItems() => new[]
9+
{
10+
new TodoItem { Description = "Walk the dog" },
11+
new TodoItem { Description = "Buy some milk" },
12+
new TodoItem { Description = "Learn Avalonia", IsChecked = true },
13+
};
14+
}
15+
}

Todo/Todo.csproj

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>WinExe</OutputType>
4+
<TargetFramework>net5.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
</PropertyGroup>
7+
<ItemGroup>
8+
<Folder Include="Models\" />
9+
<AvaloniaResource Include="Assets\**" />
10+
</ItemGroup>
11+
<ItemGroup>
12+
<PackageReference Include="Avalonia" Version="0.10.3" />
13+
<PackageReference Include="Avalonia.Desktop" Version="0.10.3" />
14+
<PackageReference Include="Avalonia.Diagnostics" Version="0.10.3" />
15+
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.3" />
16+
<PackageReference Include="Live.Avalonia" Version="1.3.1" />
17+
</ItemGroup>
18+
</Project>

Todo/ViewLocator.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using Avalonia.Controls;
2+
using Avalonia.Controls.Templates;
3+
using System;
4+
using Todo.ViewModels;
5+
6+
namespace Todo
7+
{
8+
public class ViewLocator : IDataTemplate
9+
{
10+
public bool SupportsRecycling => false;
11+
12+
public IControl Build(object data)
13+
{
14+
var name = data.GetType().FullName!.Replace("ViewModel", "View");
15+
var type = Type.GetType(name);
16+
17+
if (type != null)
18+
{
19+
return (Control)Activator.CreateInstance(type)!;
20+
}
21+
else
22+
{
23+
return new TextBlock { Text = "Not Found: " + name };
24+
}
25+
}
26+
27+
public bool Match(object data)
28+
{
29+
return data is ViewModelBase;
30+
}
31+
}
32+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using Todo.Services;
5+
6+
namespace Todo.ViewModels
7+
{
8+
public class MainWindowViewModel : ReactiveValidationObject, ViewModelBase
9+
{
10+
public MainWindowViewModel(Database db)
11+
{
12+
List = new TodoListViewModel(db.GetItems());
13+
}
14+
15+
public TodoListViewModel List { get; }
16+
}
17+
}

0 commit comments

Comments
 (0)