11/14
This commit is contained in:
15
ToDoList/App.axaml
Normal file
15
ToDoList/App.axaml
Normal file
@@ -0,0 +1,15 @@
|
||||
<Application xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
x:Class="ToDoList.App"
|
||||
xmlns:local="using:ToDoList"
|
||||
RequestedThemeVariant="Default">
|
||||
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
|
||||
|
||||
<Application.DataTemplates>
|
||||
<local:ViewLocator/>
|
||||
</Application.DataTemplates>
|
||||
|
||||
<Application.Styles>
|
||||
<FluentTheme />
|
||||
</Application.Styles>
|
||||
</Application>
|
||||
28
ToDoList/App.axaml.cs
Normal file
28
ToDoList/App.axaml.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using ToDoList.ViewModels;
|
||||
using ToDoList.Views;
|
||||
|
||||
namespace ToDoList;
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
BIN
ToDoList/Assets/avalonia-logo.ico
Normal file
BIN
ToDoList/Assets/avalonia-logo.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 172 KiB |
9
ToDoList/DataModel/ToDoItem.cs
Normal file
9
ToDoList/DataModel/ToDoItem.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using System;
|
||||
|
||||
namespace ToDoList.DataModel;
|
||||
|
||||
public class ToDoItem
|
||||
{
|
||||
public string Description { get; set; } = String.Empty;
|
||||
public bool IsChecked { get; set; }
|
||||
}
|
||||
23
ToDoList/Program.cs
Normal file
23
ToDoList/Program.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Avalonia;
|
||||
using Avalonia.ReactiveUI;
|
||||
using System;
|
||||
|
||||
namespace ToDoList;
|
||||
|
||||
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()
|
||||
.WithInterFont()
|
||||
.LogToTrace()
|
||||
.UseReactiveUI();
|
||||
}
|
||||
14
ToDoList/Services/ToDoListService.cs
Normal file
14
ToDoList/Services/ToDoListService.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
using ToDoList.DataModel;
|
||||
|
||||
namespace ToDoList.Services;
|
||||
|
||||
public class ToDoListService
|
||||
{
|
||||
public IEnumerable<ToDoItem> GetItems() => new[]
|
||||
{
|
||||
new ToDoItem { Description = "Walk the dog" },
|
||||
new ToDoItem { Description = "Buy some milk" },
|
||||
new ToDoItem { Description = "Learn Avalonia", IsChecked = true },
|
||||
};
|
||||
}
|
||||
30
ToDoList/ToDoList.csproj
Normal file
30
ToDoList/ToDoList.csproj
Normal file
@@ -0,0 +1,30 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
|
||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<AvaloniaResource Include="Assets\**"/>
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Avalonia" Version="11.0.0"/>
|
||||
<PackageReference Include="Avalonia.Desktop" Version="11.0.0"/>
|
||||
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.0"/>
|
||||
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.0.0"/>
|
||||
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
|
||||
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.0"/>
|
||||
<PackageReference Include="Avalonia.ReactiveUI" Version="11.0.0"/>
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BatchOszExtractor.Core\BatchOszExtractor.Core.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
27
ToDoList/ViewLocator.cs
Normal file
27
ToDoList/ViewLocator.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Templates;
|
||||
using ToDoList.ViewModels;
|
||||
|
||||
namespace ToDoList;
|
||||
|
||||
public class ViewLocator : IDataTemplate
|
||||
{
|
||||
public Control Build(object data)
|
||||
{
|
||||
var name = data.GetType().FullName!.Replace("ViewModel", "View");
|
||||
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;
|
||||
}
|
||||
}
|
||||
9
ToDoList/ViewModels/AddItemViewModel.cs
Normal file
9
ToDoList/ViewModels/AddItemViewModel.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using System;
|
||||
|
||||
namespace ToDoList.ViewModels
|
||||
{
|
||||
public class AddItemViewModel : ViewModelBase
|
||||
{
|
||||
public string Description { get; set; } = String.Empty;
|
||||
}
|
||||
}
|
||||
32
ToDoList/ViewModels/MainWindowViewModel.cs
Normal file
32
ToDoList/ViewModels/MainWindowViewModel.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using ReactiveUI;
|
||||
using ToDoList.Services;
|
||||
|
||||
namespace ToDoList.ViewModels
|
||||
{
|
||||
public class MainWindowViewModel : ViewModelBase
|
||||
{
|
||||
private ViewModelBase _contentViewModel;
|
||||
|
||||
//this has a dependency on the ToDoListService
|
||||
|
||||
public MainWindowViewModel()
|
||||
{
|
||||
var service = new ToDoListService();
|
||||
ToDoList = new ToDoListViewModel(service.GetItems());
|
||||
_contentViewModel = ToDoList;
|
||||
}
|
||||
|
||||
public ToDoListViewModel ToDoList { get; }
|
||||
|
||||
public ViewModelBase ContentViewModel
|
||||
{
|
||||
get => _contentViewModel;
|
||||
private set => this.RaiseAndSetIfChanged(ref _contentViewModel, value);
|
||||
}
|
||||
|
||||
public void AddItem()
|
||||
{
|
||||
ContentViewModel = new AddItemViewModel();
|
||||
}
|
||||
}
|
||||
}
|
||||
16
ToDoList/ViewModels/ToDoListViewModel.cs
Normal file
16
ToDoList/ViewModels/ToDoListViewModel.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using ToDoList.DataModel;
|
||||
|
||||
namespace ToDoList.ViewModels
|
||||
{
|
||||
public class ToDoListViewModel : ViewModelBase
|
||||
{
|
||||
public ToDoListViewModel(IEnumerable<ToDoItem> items)
|
||||
{
|
||||
ListItems = new ObservableCollection<ToDoItem>(items);
|
||||
}
|
||||
|
||||
public ObservableCollection<ToDoItem> ListItems { get; }
|
||||
}
|
||||
}
|
||||
7
ToDoList/ViewModels/ViewModelBase.cs
Normal file
7
ToDoList/ViewModels/ViewModelBase.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
using ReactiveUI;
|
||||
|
||||
namespace ToDoList.ViewModels;
|
||||
|
||||
public class ViewModelBase : ReactiveObject
|
||||
{
|
||||
}
|
||||
20
ToDoList/Views/AddItemView.axaml
Normal file
20
ToDoList/Views/AddItemView.axaml
Normal file
@@ -0,0 +1,20 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:vm="using:ToDoList.ViewModels"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d" d:DesignWidth="400" d:DesignHeight="400"
|
||||
x:DataType="vm:AddItemViewModel"
|
||||
x:Class="ToDoList.Views.AddItemView">
|
||||
<DockPanel>
|
||||
<Button DockPanel.Dock="Bottom"
|
||||
HorizontalAlignment="Stretch"
|
||||
HorizontalContentAlignment="Center">Cancel</Button>
|
||||
<Button DockPanel.Dock="Bottom"
|
||||
HorizontalAlignment="Stretch"
|
||||
HorizontalContentAlignment="Center">OK</Button>
|
||||
<TextBox AcceptsReturn="True"
|
||||
Text="{Binding Description}"
|
||||
Watermark="Enter your to do item"/>
|
||||
</DockPanel>
|
||||
</UserControl>
|
||||
13
ToDoList/Views/AddItemView.axaml.cs
Normal file
13
ToDoList/Views/AddItemView.axaml.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace ToDoList.Views;
|
||||
|
||||
public partial class AddItemView : UserControl
|
||||
{
|
||||
public AddItemView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
12
ToDoList/Views/MainWindow.axaml
Normal file
12
ToDoList/Views/MainWindow.axaml
Normal file
@@ -0,0 +1,12 @@
|
||||
<Window xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:vm="using:ToDoList.ViewModels"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d" d:DesignWidth="400" d:DesignHeight="400"
|
||||
x:Class="ToDoList.Views.MainWindow"
|
||||
x:DataType="vm:MainWindowViewModel"
|
||||
Icon="/Assets/avalonia-logo.ico"
|
||||
Title="Avalonia To Do List"
|
||||
Content="{Binding ContentViewModel}">
|
||||
</Window>
|
||||
11
ToDoList/Views/MainWindow.axaml.cs
Normal file
11
ToDoList/Views/MainWindow.axaml.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using Avalonia.Controls;
|
||||
|
||||
namespace ToDoList.Views;
|
||||
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
27
ToDoList/Views/ToDoListView.axaml
Normal file
27
ToDoList/Views/ToDoListView.axaml
Normal file
@@ -0,0 +1,27 @@
|
||||
<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"
|
||||
mc:Ignorable="d" d:DesignWidth="400" d:DesignHeight="400"
|
||||
xmlns:vm="using:ToDoList.ViewModels"
|
||||
x:DataType="vm:ToDoListViewModel"
|
||||
x:Class="ToDoList.Views.ToDoListView">
|
||||
<DockPanel>
|
||||
<Button DockPanel.Dock="Bottom"
|
||||
HorizontalAlignment="Stretch"
|
||||
HorizontalContentAlignment="Center"
|
||||
x:CompileBindings="False"
|
||||
Command="{Binding $parent[Window].DataContext.AddItem}">
|
||||
Add Item
|
||||
</Button>
|
||||
<ItemsControl ItemsSource="{Binding ListItems}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<CheckBox Margin="4"
|
||||
IsChecked="{Binding IsChecked}"
|
||||
Content="{Binding Description}"/>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</DockPanel>
|
||||
</UserControl>
|
||||
13
ToDoList/Views/ToDoListView.axaml.cs
Normal file
13
ToDoList/Views/ToDoListView.axaml.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace ToDoList.Views;
|
||||
|
||||
public partial class ToDoListView : UserControl
|
||||
{
|
||||
public ToDoListView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
18
ToDoList/app.manifest
Normal file
18
ToDoList/app.manifest
Normal file
@@ -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 embeded controls.
|
||||
For more details visit https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests -->
|
||||
<assemblyIdentity version="1.0.0.0" name="BatchOszExtractor.UI.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>
|
||||
Reference in New Issue
Block a user