diff options
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | App.axaml | 22 | ||||
| -rw-r--r-- | App.axaml.cs | 31 | ||||
| -rw-r--r-- | Assets/avalonia-logo.ico | bin | 0 -> 175875 bytes | |||
| -rw-r--r-- | Models/BidItem.cs | 8 | ||||
| -rw-r--r-- | Program.cs | 24 | ||||
| -rw-r--r-- | ViewLocator.cs | 37 | ||||
| -rw-r--r-- | ViewModels/MainWindowViewModel.cs | 25 | ||||
| -rw-r--r-- | ViewModels/ViewModelBase.cs | 7 | ||||
| -rw-r--r-- | Views/BidItemEditor.axaml | 21 | ||||
| -rw-r--r-- | Views/BidItemEditor.axaml.cs | 14 | ||||
| -rw-r--r-- | Views/MainWindow.axaml | 45 | ||||
| -rw-r--r-- | Views/MainWindow.axaml.cs | 11 | ||||
| -rw-r--r-- | app.manifest | 18 | ||||
| -rw-r--r-- | east-auctioner.csproj | 26 |
15 files changed, 291 insertions, 0 deletions
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 @@ +<Application xmlns="https://github.com/avaloniaui"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ x:Class="east_auctioner.App"
+ xmlns:local="using:east_auctioner"
+ xmlns:views="using:east_auctioner.Views"
+ xmlns:models="using:east_auctioner.Models"
+ RequestedThemeVariant="Default">
+ <!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
+
+ <Application.DataTemplates>
+ <local:ViewLocator/>
+ <DataTemplate DataType="models:BidItem">
+ <views:BidItemEditor />
+ </DataTemplate>
+
+ </Application.DataTemplates>
+
+
+ <Application.Styles>
+ <FluentTheme />
+ </Application.Styles>
+</Application>
\ 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 Binary files differnew file mode 100644 index 0000000..f7da8bb --- /dev/null +++ b/Assets/avalonia-logo.ico 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<App>()
+ .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;
+
+/// <summary>
+/// Given a view model, returns the corresponding view if possible.
+/// </summary>
+[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 @@ +<UserControl xmlns="https://github.com/avaloniaui"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ xmlns:models="using:east_auctioner.Models"
+ mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
+ x:Class="east_auctioner.Views.BidItemEditor"
+ x:DataType="models:BidItem"
+ >
+ <Grid Margin="10,50,10,50">
+ <Grid.ColumnDefinitions>
+ <ColumnDefinition Width="*"></ColumnDefinition>
+ <ColumnDefinition Width="*"></ColumnDefinition>
+ </Grid.ColumnDefinitions>
+ <Grid.RowDefinitions>
+ <RowDefinition Height="Auto"></RowDefinition>
+ </Grid.RowDefinitions>
+ <TextBlock>Name of Item:</TextBlock>
+ <TextBox Text="{Binding Title}" Grid.Column="1" />
+ </Grid>
+</UserControl>
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 @@ +<Window xmlns="https://github.com/avaloniaui"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:vm="using:east_auctioner.ViewModels"
+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ xmlns:models="using:east_auctioner.Models"
+ mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
+ x:Class="east_auctioner.Views.MainWindow"
+ x:DataType="vm:MainWindowViewModel"
+ Icon="/Assets/avalonia-logo.ico"
+ Title="Auctioner Window">
+
+ <Design.DataContext>
+ <!-- This only sets the DataContext for the previewer in an IDE,
+ to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
+ <vm:MainWindowViewModel/>
+ </Design.DataContext>
+ <Grid>
+ <Grid.ColumnDefinitions>
+ <ColumnDefinition Width="*"></ColumnDefinition>
+ <ColumnDefinition Width="*"></ColumnDefinition>
+ </Grid.ColumnDefinitions>
+ <Grid.RowDefinitions>
+ <RowDefinition Height="*"></RowDefinition>
+ </Grid.RowDefinitions>
+
+ <ListBox ItemsSource="{Binding Items}" SelectedItem="{Binding CurrentItem}" >
+ <ListBox.ItemTemplate>
+ <DataTemplate DataType="models:BidItem">
+ <StackPanel Orientation="Vertical">
+ <StackPanel Orientation="Horizontal">
+ <TextBlock>Name: </TextBlock>
+ <TextBlock Text="{Binding Title}" />
+ </StackPanel>
+ <Border Height="1" Margin="0,4,0,4" Background="Black"/>
+ </StackPanel>
+ </DataTemplate>
+ </ListBox.ItemTemplate>
+ </ListBox>
+ <ContentControl
+ Grid.Column="1"
+ Content="{Binding CurrentItem}"
+ />
+ </Grid>
+</Window>
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 @@ +<?xml version="1.0" encoding="utf-8"?>
+<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
+ <!-- This manifest is used on Windows only.
+ Don't remove it as it might cause problems with window transparency and embedded controls.
+ For more details visit https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests -->
+ <assemblyIdentity version="1.0.0.0" name="east_auctioner.Desktop"/>
+
+ <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
+ <application>
+ <!-- A list of the Windows versions that this application has been tested on
+ and is designed to work with. Uncomment the appropriate elements
+ and Windows will automatically select the most compatible environment. -->
+
+ <!-- Windows 10 -->
+ <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
+ </application>
+ </compatibility>
+</assembly>
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 @@ +<Project Sdk="Microsoft.NET.Sdk">
+ <PropertyGroup>
+ <OutputType>WinExe</OutputType>
+ <TargetFramework>net10.0</TargetFramework>
+ <Nullable>enable</Nullable>
+ <ApplicationManifest>app.manifest</ApplicationManifest>
+ <AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <Folder Include="Models\" />
+ <AvaloniaResource Include="Assets\**" />
+ </ItemGroup>
+
+ <ItemGroup>
+ <PackageReference Include="Avalonia" Version="12.0.3" />
+ <PackageReference Include="Avalonia.Desktop" Version="12.0.3" />
+ <PackageReference Include="Avalonia.Themes.Fluent" Version="12.0.3" />
+ <PackageReference Include="Avalonia.Fonts.Inter" Version="12.0.3" />
+ <PackageReference Include="AvaloniaUI.DiagnosticsSupport" Version="2.2.1">
+ <IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
+ <PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
+ </PackageReference>
+ <PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.1" />
+ </ItemGroup>
+</Project>
|
