Skip to content

Commit 6db3566

Browse files
committed
Initial commit
- Initial commit with the standard Avalonia MVVM project template.
0 parents  commit 6db3566

12 files changed

+196
-0
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
bin/
2+
obj/
3+
/packages/
4+
riderModule.iml
5+
/_ReSharper.Caches/

App.axaml

+12
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:FileTransfer"
4+
x:Class="FileTransfer.App">
5+
<Application.DataTemplates>
6+
<local:ViewLocator/>
7+
</Application.DataTemplates>
8+
9+
<Application.Styles>
10+
<FluentTheme Mode="Light"/>
11+
</Application.Styles>
12+
</Application>

App.axaml.cs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using Avalonia;
2+
using Avalonia.Controls.ApplicationLifetimes;
3+
using Avalonia.Markup.Xaml;
4+
using FileTransfer.ViewModels;
5+
using FileTransfer.Views;
6+
7+
namespace FileTransfer
8+
{
9+
public class App : Application
10+
{
11+
public override void Initialize()
12+
{
13+
AvaloniaXamlLoader.Load(this);
14+
}
15+
16+
public override void OnFrameworkInitializationCompleted()
17+
{
18+
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
19+
{
20+
desktop.MainWindow = new MainWindow
21+
{
22+
DataContext = new MainWindowViewModel(),
23+
};
24+
}
25+
26+
base.OnFrameworkInitializationCompleted();
27+
}
28+
}
29+
}

Assets/avalonia-logo.ico

172 KB
Binary file not shown.

FileTransfer.csproj

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
<None Remove=".gitignore"/>
11+
</ItemGroup>
12+
<ItemGroup>
13+
<PackageReference Include="Avalonia" Version="0.10.10"/>
14+
<PackageReference Include="Avalonia.Desktop" Version="0.10.10"/>
15+
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
16+
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="0.10.10"/>
17+
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.10"/>
18+
</ItemGroup>
19+
</Project>

FileTransfer.sln

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileTransfer", "FileTransfer.csproj", "{201C2D5F-FA4C-484E-912D-9F624711FB13}"
4+
EndProject
5+
Global
6+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
7+
Debug|Any CPU = Debug|Any CPU
8+
Release|Any CPU = Release|Any CPU
9+
EndGlobalSection
10+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
11+
{201C2D5F-FA4C-484E-912D-9F624711FB13}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
12+
{201C2D5F-FA4C-484E-912D-9F624711FB13}.Debug|Any CPU.Build.0 = Debug|Any CPU
13+
{201C2D5F-FA4C-484E-912D-9F624711FB13}.Release|Any CPU.ActiveCfg = Release|Any CPU
14+
{201C2D5F-FA4C-484E-912D-9F624711FB13}.Release|Any CPU.Build.0 = Release|Any CPU
15+
EndGlobalSection
16+
EndGlobal

Program.cs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using Avalonia;
3+
using Avalonia.Controls.ApplicationLifetimes;
4+
using Avalonia.ReactiveUI;
5+
6+
namespace FileTransfer
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+
[STAThread]
14+
public static void Main(string[] args) => BuildAvaloniaApp()
15+
.StartWithClassicDesktopLifetime(args);
16+
17+
// Avalonia configuration, don't remove; also used by visual designer.
18+
public static AppBuilder BuildAvaloniaApp()
19+
=> AppBuilder.Configure<App>()
20+
.UsePlatformDetect()
21+
.LogToTrace()
22+
.UseReactiveUI();
23+
}
24+
}

ViewLocator.cs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using Avalonia.Controls;
3+
using Avalonia.Controls.Templates;
4+
using FileTransfer.ViewModels;
5+
6+
namespace FileTransfer
7+
{
8+
public class ViewLocator : IDataTemplate
9+
{
10+
public IControl Build(object data)
11+
{
12+
var name = data.GetType().FullName!.Replace("ViewModel", "View");
13+
var type = Type.GetType(name);
14+
15+
if (type != null)
16+
{
17+
return (Control)Activator.CreateInstance(type)!;
18+
}
19+
else
20+
{
21+
return new TextBlock { Text = "Not Found: " + name };
22+
}
23+
}
24+
25+
public bool Match(object data)
26+
{
27+
return data is ViewModelBase;
28+
}
29+
}
30+
}

ViewModels/MainWindowViewModel.cs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace FileTransfer.ViewModels
6+
{
7+
public class MainWindowViewModel : ViewModelBase
8+
{
9+
public string Greeting => "Welcome to Avalonia!";
10+
}
11+
}

ViewModels/ViewModelBase.cs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using ReactiveUI;
5+
6+
namespace FileTransfer.ViewModels
7+
{
8+
public class ViewModelBase : ReactiveObject
9+
{
10+
}
11+
}

Views/MainWindow.axaml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Window xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:vm="using:FileTransfer.ViewModels"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
7+
x:Class="FileTransfer.Views.MainWindow"
8+
Icon="/Assets/avalonia-logo.ico"
9+
Title="FileTransfer">
10+
11+
<Design.DataContext>
12+
<vm:MainWindowViewModel/>
13+
</Design.DataContext>
14+
15+
<TextBlock Text="{Binding Greeting}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
16+
17+
</Window>

Views/MainWindow.axaml.cs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Avalonia;
2+
using Avalonia.Controls;
3+
using Avalonia.Markup.Xaml;
4+
5+
namespace FileTransfer.Views
6+
{
7+
public partial class MainWindow : Window
8+
{
9+
public MainWindow()
10+
{
11+
InitializeComponent();
12+
#if DEBUG
13+
this.AttachDevTools();
14+
#endif
15+
}
16+
17+
private void InitializeComponent()
18+
{
19+
AvaloniaXamlLoader.Load(this);
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)