diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cd42ee3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +bin/ +obj/ diff --git a/KeyKeeper.sln b/KeyKeeper.sln new file mode 100644 index 0000000..70ccc2e --- /dev/null +++ b/KeyKeeper.sln @@ -0,0 +1,27 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{9EB66B5E-7879-4995-8105-D0D9B55CFCB6}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KeyKeeper", "src\KeyKeeper\KeyKeeper.csproj", "{0371062D-477F-4693-9605-958EAF60CE52}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0371062D-477F-4693-9605-958EAF60CE52}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0371062D-477F-4693-9605-958EAF60CE52}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0371062D-477F-4693-9605-958EAF60CE52}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0371062D-477F-4693-9605-958EAF60CE52}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {0371062D-477F-4693-9605-958EAF60CE52} = {9EB66B5E-7879-4995-8105-D0D9B55CFCB6} + EndGlobalSection +EndGlobal diff --git a/src/KeyKeeper/App.axaml b/src/KeyKeeper/App.axaml new file mode 100644 index 0000000..bc11f2d --- /dev/null +++ b/src/KeyKeeper/App.axaml @@ -0,0 +1,15 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/KeyKeeper/App.axaml.cs b/src/KeyKeeper/App.axaml.cs new file mode 100644 index 0000000..70fc81e --- /dev/null +++ b/src/KeyKeeper/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 KeyKeeper.ViewModels; +using KeyKeeper.Views; + +namespace KeyKeeper; + +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().ToArray(); + + // remove each entry found + foreach (var plugin in dataValidationPluginsToRemove) + { + BindingPlugins.DataValidators.Remove(plugin); + } + } +} \ No newline at end of file diff --git a/src/KeyKeeper/Assets/avalonia-logo.ico b/src/KeyKeeper/Assets/avalonia-logo.ico new file mode 100644 index 0000000..f7da8bb Binary files /dev/null and b/src/KeyKeeper/Assets/avalonia-logo.ico differ diff --git a/src/KeyKeeper/KeyKeeper.csproj b/src/KeyKeeper/KeyKeeper.csproj new file mode 100644 index 0000000..8a8fdc5 --- /dev/null +++ b/src/KeyKeeper/KeyKeeper.csproj @@ -0,0 +1,28 @@ + + + WinExe + net8.0 + enable + true + app.manifest + true + + + + + + + + + + + + + + + None + All + + + + diff --git a/src/KeyKeeper/Program.cs b/src/KeyKeeper/Program.cs new file mode 100644 index 0000000..53afe67 --- /dev/null +++ b/src/KeyKeeper/Program.cs @@ -0,0 +1,21 @@ +using Avalonia; +using System; + +namespace KeyKeeper; + +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() + .UsePlatformDetect() + .WithInterFont() + .LogToTrace(); +} diff --git a/src/KeyKeeper/ViewLocator.cs b/src/KeyKeeper/ViewLocator.cs new file mode 100644 index 0000000..7bfb842 --- /dev/null +++ b/src/KeyKeeper/ViewLocator.cs @@ -0,0 +1,31 @@ +using System; +using Avalonia.Controls; +using Avalonia.Controls.Templates; +using KeyKeeper.ViewModels; + +namespace KeyKeeper; + +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/src/KeyKeeper/ViewModels/MainWindowViewModel.cs b/src/KeyKeeper/ViewModels/MainWindowViewModel.cs new file mode 100644 index 0000000..8832705 --- /dev/null +++ b/src/KeyKeeper/ViewModels/MainWindowViewModel.cs @@ -0,0 +1,6 @@ +namespace KeyKeeper.ViewModels; + +public partial class MainWindowViewModel : ViewModelBase +{ + public string Greeting { get; } = "Welcome to Avalonia!"; +} diff --git a/src/KeyKeeper/ViewModels/ViewModelBase.cs b/src/KeyKeeper/ViewModels/ViewModelBase.cs new file mode 100644 index 0000000..4c3b6ea --- /dev/null +++ b/src/KeyKeeper/ViewModels/ViewModelBase.cs @@ -0,0 +1,7 @@ +using CommunityToolkit.Mvvm.ComponentModel; + +namespace KeyKeeper.ViewModels; + +public class ViewModelBase : ObservableObject +{ +} diff --git a/src/KeyKeeper/Views/MainWindow.axaml b/src/KeyKeeper/Views/MainWindow.axaml new file mode 100644 index 0000000..ef3c097 --- /dev/null +++ b/src/KeyKeeper/Views/MainWindow.axaml @@ -0,0 +1,20 @@ + + + + + + + + + + diff --git a/src/KeyKeeper/Views/MainWindow.axaml.cs b/src/KeyKeeper/Views/MainWindow.axaml.cs new file mode 100644 index 0000000..cf65309 --- /dev/null +++ b/src/KeyKeeper/Views/MainWindow.axaml.cs @@ -0,0 +1,11 @@ +using Avalonia.Controls; + +namespace KeyKeeper.Views; + +public partial class MainWindow : Window +{ + public MainWindow() + { + InitializeComponent(); + } +} \ No newline at end of file diff --git a/src/KeyKeeper/app.manifest b/src/KeyKeeper/app.manifest new file mode 100644 index 0000000..8ac4925 --- /dev/null +++ b/src/KeyKeeper/app.manifest @@ -0,0 +1,18 @@ + + + + + + + + + + + + + +