From 064dbb3f410b2b95fede248be7b57179e762db0b Mon Sep 17 00:00:00 2001 From: uvok Date: Sat, 16 May 2026 19:40:09 +0200 Subject: Initial commit --- .gitignore | 2 ++ App.axaml | 22 +++++++++++++++++++ App.axaml.cs | 31 ++++++++++++++++++++++++++ Assets/avalonia-logo.ico | Bin 0 -> 175875 bytes Models/BidItem.cs | 8 +++++++ Program.cs | 24 ++++++++++++++++++++ ViewLocator.cs | 37 +++++++++++++++++++++++++++++++ ViewModels/MainWindowViewModel.cs | 25 +++++++++++++++++++++ ViewModels/ViewModelBase.cs | 7 ++++++ Views/BidItemEditor.axaml | 21 ++++++++++++++++++ Views/BidItemEditor.axaml.cs | 14 ++++++++++++ Views/MainWindow.axaml | 45 ++++++++++++++++++++++++++++++++++++++ Views/MainWindow.axaml.cs | 11 ++++++++++ app.manifest | 18 +++++++++++++++ east-auctioner.csproj | 26 ++++++++++++++++++++++ 15 files changed, 291 insertions(+) create mode 100644 .gitignore create mode 100644 App.axaml create mode 100644 App.axaml.cs create mode 100644 Assets/avalonia-logo.ico create mode 100644 Models/BidItem.cs create mode 100644 Program.cs create mode 100644 ViewLocator.cs create mode 100644 ViewModels/MainWindowViewModel.cs create mode 100644 ViewModels/ViewModelBase.cs create mode 100644 Views/BidItemEditor.axaml create mode 100644 Views/BidItemEditor.axaml.cs create mode 100644 Views/MainWindow.axaml create mode 100644 Views/MainWindow.axaml.cs create mode 100644 app.manifest create mode 100644 east-auctioner.csproj 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/App.axaml b/App.axaml new file mode 100644 index 0000000..44be8c1 --- /dev/null +++ b/App.axaml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/App.axaml.cs b/App.axaml.cs new file mode 100644 index 0000000..319aaf6 --- /dev/null +++ b/App.axaml.cs @@ -0,0 +1,31 @@ +using Avalonia; +using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Data.Core; +using Avalonia.Data.Core.Plugins; +using System.Linq; +using Avalonia.Markup.Xaml; +using east_auctioner.ViewModels; +using east_auctioner.Views; + +namespace east_auctioner; + +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/Assets/avalonia-logo.ico b/Assets/avalonia-logo.ico new file mode 100644 index 0000000..f7da8bb Binary files /dev/null and b/Assets/avalonia-logo.ico differ diff --git a/Models/BidItem.cs b/Models/BidItem.cs new file mode 100644 index 0000000..1828bfc --- /dev/null +++ b/Models/BidItem.cs @@ -0,0 +1,8 @@ +namespace east_auctioner.Models; + +public class BidItem +{ + public bool IsDisplayed { get; set; } + + public string Title { get; set; } = ""; +} diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..e1d7e33 --- /dev/null +++ b/Program.cs @@ -0,0 +1,24 @@ +using Avalonia; +using System; + +namespace east_auctioner; + +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() +#if DEBUG + .WithDeveloperTools() +#endif + .WithInterFont() + .LogToTrace(); +} diff --git a/ViewLocator.cs b/ViewLocator.cs new file mode 100644 index 0000000..c8b4776 --- /dev/null +++ b/ViewLocator.cs @@ -0,0 +1,37 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using Avalonia.Controls; +using Avalonia.Controls.Templates; +using east_auctioner.ViewModels; + +namespace east_auctioner; + +/// +/// Given a view model, returns the corresponding view if possible. +/// +[RequiresUnreferencedCode( + "Default implementation of ViewLocator involves reflection which may be trimmed away.", + Url = "https://docs.avaloniaui.net/docs/concepts/view-locator")] +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/ViewModels/MainWindowViewModel.cs b/ViewModels/MainWindowViewModel.cs new file mode 100644 index 0000000..8025190 --- /dev/null +++ b/ViewModels/MainWindowViewModel.cs @@ -0,0 +1,25 @@ +namespace east_auctioner.ViewModels; + +using east_auctioner.Models; + +public partial class MainWindowViewModel : ViewModelBase +{ + public string Greeting { get; } = "Welcome to Avalonia!"; + public BidItem[] Items { get; } + + private BidItem? _currentItem; + public BidItem? CurrentItem + { + get { return _currentItem; } + set { this.SetProperty(ref _currentItem, value); } + } + + public MainWindowViewModel() + { + Items = [ + new BidItem { Title = "foo" }, + new BidItem { Title = "bar" }, + new BidItem { Title = "baz" }, + ]; + } +} diff --git a/ViewModels/ViewModelBase.cs b/ViewModels/ViewModelBase.cs new file mode 100644 index 0000000..0d3c549 --- /dev/null +++ b/ViewModels/ViewModelBase.cs @@ -0,0 +1,7 @@ +using CommunityToolkit.Mvvm.ComponentModel; + +namespace east_auctioner.ViewModels; + +public abstract class ViewModelBase : ObservableObject +{ +} diff --git a/Views/BidItemEditor.axaml b/Views/BidItemEditor.axaml new file mode 100644 index 0000000..340c602 --- /dev/null +++ b/Views/BidItemEditor.axaml @@ -0,0 +1,21 @@ + + + + + + + + + + Name of Item: + + + diff --git a/Views/BidItemEditor.axaml.cs b/Views/BidItemEditor.axaml.cs new file mode 100644 index 0000000..37bf04e --- /dev/null +++ b/Views/BidItemEditor.axaml.cs @@ -0,0 +1,14 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; +using east_auctioner.Models; + +namespace east_auctioner.Views; + +public partial class BidItemEditor : UserControl +{ + public BidItemEditor() + { + InitializeComponent(); + } +} diff --git a/Views/MainWindow.axaml b/Views/MainWindow.axaml new file mode 100644 index 0000000..ec1472b --- /dev/null +++ b/Views/MainWindow.axaml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + Name: + + + + + + + + + + diff --git a/Views/MainWindow.axaml.cs b/Views/MainWindow.axaml.cs new file mode 100644 index 0000000..12b598c --- /dev/null +++ b/Views/MainWindow.axaml.cs @@ -0,0 +1,11 @@ +using Avalonia.Controls; + +namespace east_auctioner.Views; + +public partial class MainWindow : Window +{ + public MainWindow() + { + InitializeComponent(); + } +} \ No newline at end of file diff --git a/app.manifest b/app.manifest new file mode 100644 index 0000000..8037ec1 --- /dev/null +++ b/app.manifest @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + diff --git a/east-auctioner.csproj b/east-auctioner.csproj new file mode 100644 index 0000000..0ca0643 --- /dev/null +++ b/east-auctioner.csproj @@ -0,0 +1,26 @@ + + + WinExe + net10.0 + enable + app.manifest + true + + + + + + + + + + + + + + None + All + + + + -- cgit v1.2.3