diff --git a/GetStartedApp/App.axaml b/GetStartedApp/App.axaml new file mode 100644 index 0000000..77ec138 --- /dev/null +++ b/GetStartedApp/App.axaml @@ -0,0 +1,15 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/GetStartedApp/App.axaml.cs b/GetStartedApp/App.axaml.cs new file mode 100644 index 0000000..b070be6 --- /dev/null +++ b/GetStartedApp/App.axaml.cs @@ -0,0 +1,28 @@ +using Avalonia; +using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Markup.Xaml; +using GetStartedApp.ViewModels; +using GetStartedApp.Views; + +namespace GetStartedApp; + +public partial class App : Application +{ + public override void Initialize() + { + AvaloniaXamlLoader.Load(this); + } + + public override void OnFrameworkInitializationCompleted() + { + if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) + { + desktop.MainWindow = new MainWindow + { + DataContext = new MainWindowViewModel(), + }; + } + + base.OnFrameworkInitializationCompleted(); + } +} \ No newline at end of file diff --git a/GetStartedApp/Assets/avalonia-logo.ico b/GetStartedApp/Assets/avalonia-logo.ico new file mode 100644 index 0000000..da8d49f Binary files /dev/null and b/GetStartedApp/Assets/avalonia-logo.ico differ diff --git a/GetStartedApp/GetStartedApp.csproj b/GetStartedApp/GetStartedApp.csproj new file mode 100644 index 0000000..254c5f1 --- /dev/null +++ b/GetStartedApp/GetStartedApp.csproj @@ -0,0 +1,25 @@ + + + WinExe + net8.0 + enable + true + app.manifest + true + + + + + + + + + + + + + + + + + diff --git a/GetStartedApp/Program.cs b/GetStartedApp/Program.cs new file mode 100644 index 0000000..792725e --- /dev/null +++ b/GetStartedApp/Program.cs @@ -0,0 +1,23 @@ +using Avalonia; +using Avalonia.ReactiveUI; +using System; + +namespace GetStartedApp; + +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() + .UseReactiveUI(); +} diff --git a/GetStartedApp/ViewLocator.cs b/GetStartedApp/ViewLocator.cs new file mode 100644 index 0000000..87f5a57 --- /dev/null +++ b/GetStartedApp/ViewLocator.cs @@ -0,0 +1,33 @@ +using System; +using Avalonia.Controls; +using Avalonia.Controls.Templates; +using GetStartedApp.ViewModels; + +namespace GetStartedApp; + +public class ViewLocator : IDataTemplate +{ + + public Control? Build(object? data) + { + if (data is null) + return null; + + var name = data.GetType().FullName!.Replace("ViewModel", "View", StringComparison.Ordinal); + var type = Type.GetType(name); + + if (type != null) + { + var control = (Control)Activator.CreateInstance(type)!; + control.DataContext = data; + return control; + } + + return new TextBlock { Text = "Not Found: " + name }; + } + + public bool Match(object? data) + { + return data is ViewModelBase; + } +} diff --git a/GetStartedApp/ViewModels/MainWindowViewModel.cs b/GetStartedApp/ViewModels/MainWindowViewModel.cs new file mode 100644 index 0000000..e693b16 --- /dev/null +++ b/GetStartedApp/ViewModels/MainWindowViewModel.cs @@ -0,0 +1,8 @@ +namespace GetStartedApp.ViewModels; + +public class MainWindowViewModel : ViewModelBase +{ +#pragma warning disable CA1822 // Mark members as static + public string Greeting => "Welcome to asdf Avalonia!"; +#pragma warning restore CA1822 // Mark members as static +} diff --git a/GetStartedApp/ViewModels/ViewModelBase.cs b/GetStartedApp/ViewModels/ViewModelBase.cs new file mode 100644 index 0000000..f581440 --- /dev/null +++ b/GetStartedApp/ViewModels/ViewModelBase.cs @@ -0,0 +1,7 @@ +using ReactiveUI; + +namespace GetStartedApp.ViewModels; + +public class ViewModelBase : ReactiveObject +{ +} diff --git a/GetStartedApp/Views/MainWindow.axaml b/GetStartedApp/Views/MainWindow.axaml new file mode 100644 index 0000000..d080edf --- /dev/null +++ b/GetStartedApp/Views/MainWindow.axaml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/GetStartedApp/Views/MainWindow.axaml.cs b/GetStartedApp/Views/MainWindow.axaml.cs new file mode 100644 index 0000000..fc412eb --- /dev/null +++ b/GetStartedApp/Views/MainWindow.axaml.cs @@ -0,0 +1,28 @@ +using Avalonia.Controls; +using Avalonia.Interactivity; +using System.Diagnostics; +using System; + +namespace GetStartedApp.Views; + +public partial class MainWindow : Window +{ + public MainWindow() + { + InitializeComponent(); + } + + public void ButtonClicked(object source, RoutedEventArgs args) + { + if (Double.TryParse(celsius.Text, out double C)) + { + var F = C * (9d / 5d) + 32; + fahrenheit.Text = F.ToString("0.0"); + } + else + { + celsius.Text = "0"; + fahrenheit.Text = "0"; + } + } +} \ No newline at end of file diff --git a/GetStartedApp/app.manifest b/GetStartedApp/app.manifest new file mode 100644 index 0000000..7597a83 --- /dev/null +++ b/GetStartedApp/app.manifest @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + diff --git a/Stars Assistant/App.axaml b/Stars Assistant/App.axaml new file mode 100644 index 0000000..d7f228d --- /dev/null +++ b/Stars Assistant/App.axaml @@ -0,0 +1,15 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Stars Assistant/App.axaml.cs b/Stars Assistant/App.axaml.cs new file mode 100644 index 0000000..83c81af --- /dev/null +++ b/Stars Assistant/App.axaml.cs @@ -0,0 +1,28 @@ +using Avalonia; +using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Markup.Xaml; +using net.nehmer.sa.ViewModels; +using net.nehmer.sa.Views; + +namespace net.nehmer.sa; + +public partial class App : Application +{ + public override void Initialize() + { + AvaloniaXamlLoader.Load(this); + } + + public override void OnFrameworkInitializationCompleted() + { + if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) + { + desktop.MainWindow = new MainWindow + { + DataContext = new MainWindowViewModel(), + }; + } + + base.OnFrameworkInitializationCompleted(); + } +} \ No newline at end of file diff --git a/Stars Assistant/Assets/avalonia-logo.ico b/Stars Assistant/Assets/avalonia-logo.ico new file mode 100644 index 0000000..da8d49f Binary files /dev/null and b/Stars Assistant/Assets/avalonia-logo.ico differ diff --git a/Stars Assistant/Program.cs b/Stars Assistant/Program.cs index b64570a..3b890cc 100644 --- a/Stars Assistant/Program.cs +++ b/Stars Assistant/Program.cs @@ -1,12 +1,34 @@ using System; -using System.Globalization; -using System.Linq; +using Avalonia; +using Avalonia.ReactiveUI; + +namespace net.nehmer.sa; + +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() + .UseReactiveUI(); +} + + +/* using Microsoft.EntityFrameworkCore; using CsvHelper.Configuration; using CsvHelper; - using net.nehmer.sa.model; -using System.Text; + using var db = new StarsDatabase("stars.sqlite"); @@ -31,6 +53,7 @@ using (var csv = new CsvReader(reader, config)) } db.SaveChanges(); } +*/ /* // Create diff --git a/Stars Assistant/Stars Assistant.csproj b/Stars Assistant/Stars Assistant.csproj index f091885..dd95249 100644 --- a/Stars Assistant/Stars Assistant.csproj +++ b/Stars Assistant/Stars Assistant.csproj @@ -6,11 +6,29 @@ net.nehmer.sa enable enable + true + app.manifest + true + + + + + + + + + + + + + diff --git a/Stars Assistant/ViewLocator.cs b/Stars Assistant/ViewLocator.cs new file mode 100644 index 0000000..ad094ea --- /dev/null +++ b/Stars Assistant/ViewLocator.cs @@ -0,0 +1,33 @@ +using System; +using Avalonia.Controls; +using Avalonia.Controls.Templates; +using net.nehmer.sa.ViewModels; + +namespace net.nehmer.sa; + +public class ViewLocator : IDataTemplate +{ + + public Control? Build(object? data) + { + if (data is null) + return null; + + var name = data.GetType().FullName!.Replace("ViewModel", "View", StringComparison.Ordinal); + var type = Type.GetType(name); + + if (type != null) + { + var control = (Control)Activator.CreateInstance(type)!; + control.DataContext = data; + return control; + } + + return new TextBlock { Text = "Not Found: " + name }; + } + + public bool Match(object? data) + { + return data is ViewModelBase; + } +} diff --git a/Stars Assistant/ViewModels/MainWindowViewModel.cs b/Stars Assistant/ViewModels/MainWindowViewModel.cs new file mode 100644 index 0000000..a00aa19 --- /dev/null +++ b/Stars Assistant/ViewModels/MainWindowViewModel.cs @@ -0,0 +1,8 @@ +namespace net.nehmer.sa.ViewModels; + +public class MainWindowViewModel : ViewModelBase +{ +#pragma warning disable CA1822 // Mark members as static + public string Greeting => "Welcome to Stars Assistant!"; +#pragma warning restore CA1822 // Mark members as static +} diff --git a/Stars Assistant/ViewModels/ViewModelBase.cs b/Stars Assistant/ViewModels/ViewModelBase.cs new file mode 100644 index 0000000..a245a88 --- /dev/null +++ b/Stars Assistant/ViewModels/ViewModelBase.cs @@ -0,0 +1,7 @@ +using ReactiveUI; + +namespace net.nehmer.sa.ViewModels; + +public class ViewModelBase : ReactiveObject +{ +} diff --git a/Stars Assistant/Views/MainWindow.axaml b/Stars Assistant/Views/MainWindow.axaml new file mode 100644 index 0000000..9c307e7 --- /dev/null +++ b/Stars Assistant/Views/MainWindow.axaml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Stars Assistant/Views/MainWindow.axaml.cs b/Stars Assistant/Views/MainWindow.axaml.cs new file mode 100644 index 0000000..d6793f6 --- /dev/null +++ b/Stars Assistant/Views/MainWindow.axaml.cs @@ -0,0 +1,28 @@ +using Avalonia.Controls; +using Avalonia.Interactivity; +using System.Diagnostics; +using System; + +namespace net.nehmer.sa.Views; + +public partial class MainWindow : Window +{ + public MainWindow() + { + InitializeComponent(); + } + + public void ButtonClicked(object source, RoutedEventArgs args) + { + if (Double.TryParse(celsius.Text, out double C)) + { + var F = C * (9d / 5d) + 32; + fahrenheit.Text = F.ToString("0.0"); + } + else + { + celsius.Text = "0"; + fahrenheit.Text = "0"; + } + } +} \ No newline at end of file diff --git a/Stars Assistant/app.manifest b/Stars Assistant/app.manifest new file mode 100644 index 0000000..007b3b4 --- /dev/null +++ b/Stars Assistant/app.manifest @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + diff --git a/Stars Assistant/demo.cs b/Stars Assistant/demo.cs deleted file mode 100644 index dbbc483..0000000 --- a/Stars Assistant/demo.cs +++ /dev/null @@ -1,39 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; - -public class BloggingContext : DbContext -{ - public DbSet Blogs { get; set; } - public DbSet Posts { get; set; } - - public string DbPath { get; } - - public BloggingContext() - { - DbPath = "./test.sqlite"; - } - - // The following configures EF to create a Sqlite database file in the - // special "local" folder for your platform. - protected override void OnConfiguring(DbContextOptionsBuilder options) - => options.UseSqlite($"Data Source={DbPath}"); -} - -public class Blog -{ - public int BlogId { get; set; } - public string Url { get; set; } - - public List Posts { get; } = new(); -} - -public class Post -{ - public int PostId { get; set; } - public string Title { get; set; } - public string Content { get; set; } - - public int BlogId { get; set; } - public Blog Blog { get; set; } -} \ No newline at end of file