Ionite
1 year ago
16 changed files with 492 additions and 0 deletions
@ -0,0 +1,16 @@
|
||||
<Application xmlns="https://github.com/avaloniaui" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
x:Class="StabilityMatrix.Avalonia.App" |
||||
xmlns:local="using:StabilityMatrix.Avalonia" |
||||
xmlns:styling="clr-namespace:FluentAvalonia.Styling;assembly=FluentAvalonia" |
||||
RequestedThemeVariant="Default"> |
||||
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. --> |
||||
|
||||
<Application.DataTemplates> |
||||
<local:ViewLocator/> |
||||
</Application.DataTemplates> |
||||
|
||||
<Application.Styles> |
||||
<styling:FluentAvaloniaTheme /> |
||||
</Application.Styles> |
||||
</Application> |
@ -0,0 +1,64 @@
|
||||
using System; |
||||
using System.Diagnostics.CodeAnalysis; |
||||
using Avalonia; |
||||
using Avalonia.Controls; |
||||
using Avalonia.Controls.ApplicationLifetimes; |
||||
using Avalonia.Markup.Xaml; |
||||
using Avalonia.Styling; |
||||
using Microsoft.Extensions.DependencyInjection; |
||||
using StabilityMatrix.Avalonia.ViewModels; |
||||
using StabilityMatrix.Avalonia.Views; |
||||
|
||||
namespace StabilityMatrix.Avalonia; |
||||
|
||||
public partial class App : Application |
||||
{ |
||||
public static IServiceProvider Services { get; set; } = null!; |
||||
|
||||
|
||||
public override void Initialize() |
||||
{ |
||||
AvaloniaXamlLoader.Load(this); |
||||
|
||||
// Set design theme |
||||
if (Design.IsDesignMode) |
||||
{ |
||||
RequestedThemeVariant = ThemeVariant.Dark; |
||||
} |
||||
} |
||||
|
||||
public override void OnFrameworkInitializationCompleted() |
||||
{ |
||||
ConfigureServiceProvider(); |
||||
|
||||
var mainViewModel = Services.GetRequiredService<MainWindowViewModel>(); |
||||
|
||||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) |
||||
{ |
||||
desktop.MainWindow = new MainWindow |
||||
{ |
||||
DataContext = mainViewModel |
||||
}; |
||||
} |
||||
|
||||
base.OnFrameworkInitializationCompleted(); |
||||
} |
||||
|
||||
private static void ConfigureServiceProvider() |
||||
{ |
||||
var services = ConfigureServices(); |
||||
Services = services.BuildServiceProvider(); |
||||
} |
||||
|
||||
private static IServiceCollection ConfigureServices() |
||||
{ |
||||
var services = new ServiceCollection(); |
||||
|
||||
services.AddSingleton<MainWindowViewModel>(); |
||||
services.AddSingleton<LaunchPageViewModel>(); |
||||
|
||||
services.AddTransient<LaunchPageView>(); |
||||
|
||||
return services; |
||||
} |
||||
} |
After Width: | Height: | Size: 172 KiB |
@ -0,0 +1,24 @@
|
||||
using Avalonia; |
||||
using System; |
||||
using System.Diagnostics.CodeAnalysis; |
||||
|
||||
namespace StabilityMatrix.Avalonia; |
||||
|
||||
[SuppressMessage("ReSharper", "ClassNeverInstantiated.Global")] |
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] |
||||
public 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(); |
||||
} |
@ -0,0 +1,28 @@
|
||||
<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> |
||||
<Folder Include="Controls\" /> |
||||
<Folder Include="Models\"/> |
||||
<AvaloniaResource Include="Assets\**"/> |
||||
</ItemGroup> |
||||
|
||||
|
||||
<ItemGroup> |
||||
<PackageReference Include="Avalonia" Version="11.0.0"/> |
||||
<PackageReference Include="Avalonia.Desktop" 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="CommunityToolkit.Mvvm" Version="8.2.1" /> |
||||
<PackageReference Include="FluentAvaloniaUI" Version="2.0.0-rc1" /> |
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" /> |
||||
</ItemGroup> |
||||
</Project> |
@ -0,0 +1,34 @@
|
||||
using System; |
||||
using Avalonia.Controls; |
||||
using Avalonia.Controls.Templates; |
||||
using StabilityMatrix.Avalonia.ViewModels; |
||||
|
||||
namespace StabilityMatrix.Avalonia; |
||||
|
||||
public class ViewLocator : IDataTemplate |
||||
{ |
||||
public Control Build(object? data) |
||||
{ |
||||
if (data is null) throw new ArgumentNullException(nameof(data)); |
||||
|
||||
var name = data.GetType().FullName!.Replace("ViewModel", "View"); |
||||
var type = Type.GetType(name); |
||||
|
||||
// Get from DI |
||||
if (type is not null) |
||||
{ |
||||
var view = App.Services.GetService(type); |
||||
if (view is not null) |
||||
{ |
||||
return (Control) view; |
||||
} |
||||
} |
||||
|
||||
return new TextBlock {Text = "Not Found: " + name}; |
||||
} |
||||
|
||||
public bool Match(object? data) |
||||
{ |
||||
return data is ViewModelBase; |
||||
} |
||||
} |
@ -0,0 +1,19 @@
|
||||
using System; |
||||
|
||||
namespace StabilityMatrix.Avalonia.ViewModels; |
||||
|
||||
public partial class LaunchPageViewModel : PageViewModelBase |
||||
{ |
||||
/// <summary> |
||||
/// The Title of this page |
||||
/// </summary> |
||||
public string Title => "Welcome to our Wizard-Sample."; |
||||
|
||||
/// <summary> |
||||
/// The content of this page |
||||
/// </summary> |
||||
public string Message => "Press \"Next\" to register yourself."; |
||||
|
||||
public override bool CanNavigateNext { get; protected set; } |
||||
public override bool CanNavigatePrevious { get; protected set; } |
||||
} |
@ -0,0 +1,32 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using Avalonia.Controls; |
||||
using CommunityToolkit.Mvvm.ComponentModel; |
||||
|
||||
namespace StabilityMatrix.Avalonia.ViewModels; |
||||
|
||||
public partial class MainWindowViewModel : ViewModelBase |
||||
{ |
||||
public string Greeting => "Welcome to Avalonia!"; |
||||
|
||||
[ObservableProperty] |
||||
private PageViewModelBase? currentPage; |
||||
|
||||
public List<PageViewModelBase> Pages { get; } = new(); |
||||
|
||||
public MainWindowViewModel(LaunchPageViewModel launchPageViewModel) |
||||
{ |
||||
Pages.Add(launchPageViewModel); |
||||
CurrentPage = Pages[0]; |
||||
} |
||||
|
||||
public MainWindowViewModel() |
||||
{ |
||||
if (!Design.IsDesignMode) |
||||
{ |
||||
throw new InvalidOperationException("Default Constructor is only for design-time."); |
||||
} |
||||
Pages.Add(new LaunchPageViewModel()); |
||||
CurrentPage = Pages[0]; |
||||
} |
||||
} |
@ -0,0 +1,17 @@
|
||||
namespace StabilityMatrix.Avalonia.ViewModels; |
||||
|
||||
/// <summary> |
||||
/// An abstract class for enabling page navigation. |
||||
/// </summary> |
||||
public abstract class PageViewModelBase : ViewModelBase |
||||
{ |
||||
/// <summary> |
||||
/// Gets if the user can navigate to the next page |
||||
/// </summary> |
||||
public abstract bool CanNavigateNext { get; protected set; } |
||||
|
||||
/// <summary> |
||||
/// Gets if the user can navigate to the previous page |
||||
/// </summary> |
||||
public abstract bool CanNavigatePrevious { get; protected set; } |
||||
} |
@ -0,0 +1,27 @@
|
||||
using System; |
||||
using System.ComponentModel.DataAnnotations; |
||||
using CommunityToolkit.Mvvm.ComponentModel; |
||||
|
||||
namespace StabilityMatrix.Avalonia.ViewModels; |
||||
|
||||
/// <summary> |
||||
/// This is our ViewModel for the second page |
||||
/// </summary> |
||||
partial class SecondPageViewModel : PageViewModelBase |
||||
{ |
||||
public SecondPageViewModel() |
||||
{ |
||||
} |
||||
|
||||
[Required] |
||||
[EmailAddress] |
||||
[ObservableProperty] |
||||
private string? mailAddress; |
||||
|
||||
[Required] |
||||
[ObservableProperty] |
||||
private string? password; |
||||
|
||||
public override bool CanNavigateNext { get; protected set; } = true; |
||||
public override bool CanNavigatePrevious { get; protected set; } |
||||
} |
@ -0,0 +1,7 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel; |
||||
|
||||
namespace StabilityMatrix.Avalonia.ViewModels; |
||||
|
||||
public class ViewModelBase : ObservableValidator |
||||
{ |
||||
} |
@ -0,0 +1,129 @@
|
||||
<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:vm="clr-namespace:StabilityMatrix.Avalonia.ViewModels" |
||||
xmlns:views="using:StabilityMatrix.Avalonia.Views" |
||||
xmlns:ui="using:FluentAvalonia.UI.Controls" |
||||
x:CompileBindings="True" |
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" |
||||
x:Class="StabilityMatrix.Avalonia.Views.LaunchPageView"> |
||||
<Design.DataContext> |
||||
<vm:LaunchPageViewModel /> |
||||
</Design.DataContext> |
||||
|
||||
<Grid RowDefinitions="Auto,*,Auto"> |
||||
<Grid ColumnDefinitions="Auto,*"> |
||||
<Grid ColumnDefinitions="0.8*,0.2*"> |
||||
<!--<ui:Flyout |
||||
Background="{DynamicResource SystemAccentColorPrimaryBrush}" |
||||
FontSize="18" |
||||
Grid.Column="0" |
||||
Grid.Row="0" |
||||
IsOpen="{Binding IsLaunchTeachingTipsOpen, Mode=TwoWay}" |
||||
Margin="24,8,0,0" |
||||
Placement="Bottom"> |
||||
<StackPanel Orientation="Horizontal"> |
||||
<Grid HorizontalAlignment="Left"> |
||||
<ui:SymbolIcon Symbol="ArrowCurveUpLeft20" /> |
||||
</Grid> |
||||
<TextBlock |
||||
HorizontalAlignment="Left" |
||||
Text="Click Launch to get started!" |
||||
TextWrapping="WrapWithOverflow" |
||||
Width="280" /> |
||||
</StackPanel> |
||||
</ui:Flyout>--> |
||||
|
||||
<!-- Command="{Binding LaunchCommand}" --> |
||||
<!--Visibility="{Binding LaunchButtonVisibility, FallbackValue=Visible}"--> |
||||
<Button |
||||
Content="Launch" |
||||
Grid.Column="0" |
||||
Grid.Row="0" |
||||
HorizontalAlignment="Left" |
||||
Margin="24,8,0,0" |
||||
VerticalAlignment="Stretch" |
||||
Width="72"/> |
||||
<!--Command="{Binding StopCommand}"--> |
||||
<!--Visibility="{Binding StopButtonVisibility, FallbackValue=Hidden}"--> |
||||
<Button |
||||
IsVisible="False" |
||||
Content="Stop" |
||||
Grid.Column="0" |
||||
Grid.Row="0" |
||||
HorizontalAlignment="Left" |
||||
Margin="24,8,0,0" |
||||
VerticalAlignment="Stretch" |
||||
Width="72"/> |
||||
<!--Command="{Binding ConfigCommand}"--> |
||||
<Button |
||||
FontSize="16" |
||||
Grid.Column="1" |
||||
Grid.Row="0" |
||||
HorizontalAlignment="Left" |
||||
Margin="8,8,0,0" |
||||
VerticalAlignment="Stretch" |
||||
Width="48"> |
||||
<ui:SymbolIcon Symbol="Settings" FontSize="16"/> |
||||
<!--<ui:Button.Icon> |
||||
<ui:SymbolIcon Symbol="Settings32" /> |
||||
</ui:Button.Icon>--> |
||||
</Button> |
||||
</Grid> |
||||
<!--ItemsSource="{Binding InstalledPackages}"--> |
||||
<!--SelectedValue="{Binding SelectedPackage}"--> |
||||
<ComboBox |
||||
Grid.Column="1" |
||||
Grid.Row="0" |
||||
HorizontalAlignment="Stretch" |
||||
Margin="8,8,24,0" |
||||
VerticalAlignment="Top" |
||||
x:Name="SelectPackageComboBox"> |
||||
<!--<ComboBox.ItemContainerStyle> |
||||
<Style TargetType="ComboBoxItem"> |
||||
<Setter Property="Template" Value="{StaticResource SelectPackageDropDownStyle}" /> |
||||
</Style> |
||||
</ComboBox.ItemContainerStyle>--> |
||||
|
||||
<!--<ComboBox.ItemTemplate> |
||||
<DataTemplate DataType="{x:Type models:InstalledPackage}"> |
||||
<StackPanel Margin="10,0,0,0" VerticalAlignment="Top"> |
||||
<TextBlock |
||||
Margin="0,5,0,5" |
||||
Name="NameTextBlock" |
||||
Text="{Binding DisplayName, Mode=OneWay}" /> |
||||
</StackPanel> |
||||
</DataTemplate> |
||||
</ComboBox.ItemTemplate>--> |
||||
</ComboBox> |
||||
</Grid> |
||||
<SelectableTextBlock |
||||
Margin="24,16" |
||||
Text="Console output here." |
||||
Grid.Row="1"> |
||||
</SelectableTextBlock> |
||||
<!--<terminal:Terminal Grid.Row="1" |
||||
Margin="24,8,26,10" |
||||
Background="{DynamicResource ControlFillColorDisabledBrush}" |
||||
IsReadOnly="True" |
||||
AutoScroll="True" |
||||
FontFamily="Consolas" |
||||
ItemHeight="22" |
||||
Foreground="White" |
||||
BorderThickness="0" |
||||
VerticalScrollBarVisibility="Auto" |
||||
ItemsSource="{Binding ConsoleHistory, Mode=OneWay}"/>--> |
||||
|
||||
<!--Command="{Binding LaunchWebUiCommand}"--> |
||||
<!--Visibility="{Binding ShowWebUiButton, Converter={StaticResource BoolToVisConverter}}"--> |
||||
<Button |
||||
Content="Open Web UI" |
||||
FontSize="12" |
||||
Grid.ColumnSpan="2" |
||||
Grid.Row="2" |
||||
HorizontalAlignment="Stretch" |
||||
Margin="24,0,24,8"/> |
||||
</Grid> |
||||
|
||||
</UserControl> |
@ -0,0 +1,18 @@
|
||||
using Avalonia; |
||||
using Avalonia.Controls; |
||||
using Avalonia.Markup.Xaml; |
||||
|
||||
namespace StabilityMatrix.Avalonia.Views; |
||||
|
||||
public partial class LaunchPageView : UserControl |
||||
{ |
||||
public LaunchPageView() |
||||
{ |
||||
InitializeComponent(); |
||||
} |
||||
|
||||
private void InitializeComponent() |
||||
{ |
||||
AvaloniaXamlLoader.Load(this); |
||||
} |
||||
} |
@ -0,0 +1,47 @@
|
||||
<Window xmlns="https://github.com/avaloniaui" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
xmlns:vm="using:StabilityMatrix.Avalonia.ViewModels" |
||||
xmlns:views="using:StabilityMatrix.Avalonia.Views" |
||||
xmlns:ui="using:FluentAvalonia.UI.Controls" |
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" |
||||
x:CompileBindings="True" |
||||
x:Class="StabilityMatrix.Avalonia.Views.MainWindow" |
||||
x:DataType="vm:MainWindowViewModel" |
||||
Icon="/Assets/avalonia-logo.ico" |
||||
Title="StabilityMatrix.Avalonia"> |
||||
|
||||
<Design.DataContext> |
||||
<vm:MainWindowViewModel/> |
||||
</Design.DataContext> |
||||
|
||||
<Grid RowDefinitions="Auto,*"> |
||||
<ui:NavigationView AlwaysShowHeader="False" |
||||
PaneDisplayMode="Left" |
||||
Grid.RowSpan="2" |
||||
Content="{Binding CurrentPage}" |
||||
MenuItemsSource="{Binding Pages, Mode=OneWay}" |
||||
IsSettingsVisible="True" |
||||
IsBackEnabled="True"> |
||||
|
||||
<ui:NavigationView.MenuItemTemplate> |
||||
<DataTemplate> |
||||
<ui:NavigationViewItem |
||||
Tag="LaunchPageView" |
||||
IsSelected="True" |
||||
Content="Launch"/> |
||||
</DataTemplate> |
||||
</ui:NavigationView.MenuItemTemplate> |
||||
|
||||
<ui:NavigationView.ContentTemplate> |
||||
<DataTemplate DataType="{x:Type vm:PageViewModelBase}"> |
||||
<ContentControl Content="{Binding}" /> |
||||
</DataTemplate> |
||||
</ui:NavigationView.ContentTemplate> |
||||
<ui:NavigationView.DataTemplates> |
||||
<!-- Define your DataTemplates here, could also use ContentTemplate if only 1 template is needed --> |
||||
</ui:NavigationView.DataTemplates> |
||||
</ui:NavigationView> |
||||
</Grid> |
||||
</Window> |
@ -0,0 +1,12 @@
|
||||
using Avalonia.Controls; |
||||
using StabilityMatrix.Avalonia.ViewModels; |
||||
|
||||
namespace StabilityMatrix.Avalonia.Views; |
||||
|
||||
public partial class MainWindow : Window |
||||
{ |
||||
public MainWindow() |
||||
{ |
||||
InitializeComponent(); |
||||
} |
||||
} |
@ -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="StabilityMatrix.Avalonia.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> |
Loading…
Reference in new issue