Merge pull request #26 from maxkatz6/master

Update to Avalonia 11 with some AOT improvements
This commit is contained in:
Todor Totev 2022-11-25 20:29:47 +02:00 committed by GitHub
commit 5ee6979980
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 232 additions and 382 deletions

View File

@ -16,7 +16,7 @@ jobs:
- name: Setup .NET - name: Setup .NET
uses: actions/setup-dotnet@v1 uses: actions/setup-dotnet@v1
with: with:
dotnet-version: 6.0.x dotnet-version: 7.0.x
- name: Publish - name: Publish
run: | run: |
sudo chmod +x ./test.sh sudo chmod +x ./test.sh
@ -25,9 +25,9 @@ jobs:
with: with:
name: Linux-Artifact name: Linux-Artifact
path: | path: |
./src/bin/x64/Release/net6.0/linux-x64/publish/*.bin ./src/bin/x64/Release/net7.0/linux-x64/publish/*.bin
./src/bin/x64/Release/net6.0/linux-x64/publish/*.so ./src/bin/x64/Release/net7.0/linux-x64/publish/*.so
./src/bin/x64/Release/net6.0/linux-x64/publish/*.png ./src/bin/x64/Release/net7.0/linux-x64/publish/*.png
build-on-windows: build-on-windows:
runs-on: windows-latest runs-on: windows-latest
steps: steps:
@ -35,16 +35,16 @@ jobs:
- name: Setup .NET - name: Setup .NET
uses: actions/setup-dotnet@v1 uses: actions/setup-dotnet@v1
with: with:
dotnet-version: 6.0.x dotnet-version: 7.0.x
- name: Publish - name: Publish
run: ./test.cmd run: ./test.cmd
- uses: actions/upload-artifact@v2 - uses: actions/upload-artifact@v2
with: with:
name: Windows-Artifact name: Windows-Artifact
path: | path: |
.\src\bin\x64\Release\net6.0\win-x64\publish\*.exe .\src\bin\x64\Release\net7.0\win-x64\publish\*.exe
.\src\bin\x64\Release\net6.0\win-x64\publish\*.dll .\src\bin\x64\Release\net7.0\win-x64\publish\*.dll
.\src\bin\x64\Release\net6.0\win-x64\publish\*.png .\src\bin\x64\Release\net7.0\win-x64\publish\*.png
build-on-macos: build-on-macos:
runs-on: macos-latest runs-on: macos-latest
steps: steps:
@ -52,12 +52,12 @@ jobs:
- name: Setup .NET - name: Setup .NET
uses: actions/setup-dotnet@v1 uses: actions/setup-dotnet@v1
with: with:
dotnet-version: 6.0.x dotnet-version: 7.0.x
- name: Publish - name: Publish
run: | run: |
sudo chmod +x ./test.command sudo chmod +x ./test.command
./test.command ./test.command
cd ./src/bin/x64/Release/net6.0/osx-x64/publish cd ./src/bin/x64/Release/net7.0/osx-x64/publish
zip -r -0 macOS-Artifact.zip *.app zip -r -0 macOS-Artifact.zip *.app
mv *.zip ../../../../../../../. mv *.zip ../../../../../../../.
- uses: actions/upload-artifact@v2 - uses: actions/upload-artifact@v2

View File

@ -1,18 +1,10 @@
<Application xmlns="https://github.com/avaloniaui" <Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="AvaloniaCoreRTDemo.App"> x:Class="AvaloniaCoreRTDemo.App">
<NativeMenu.Menu>
<NativeMenu>
<NativeMenuItem Header="About" Gesture="cmd+b" IsEnabled="{Binding AboutEnabled}" Command="{Binding HelpAboutMethod}"/>
</NativeMenu>
</NativeMenu.Menu>
<Application.Styles>
<StyleInclude Source="avares://Avalonia.Themes.Default/Accents/BaseDark.xaml"/>
<StyleInclude Source="avares://Avalonia.Themes.Default/Accents/BaseLight.xaml"/>
<StyleInclude Source="avares://Avalonia.Themes.Default/DefaultTheme.xaml"/>
</Application.Styles>
<Application.Resources> <Application.Resources>
<FluentTheme x:Key="fluentLight" Mode="Light" /> <StyleInclude x:Key="fluentDataGrid" Source="avares://Avalonia.Controls.DataGrid/Themes/Fluent.xaml" />
<FluentTheme x:Key="fluentDark" Mode="Dark" /> <StyleInclude x:Key="simpleDataGrid" Source="avares://Avalonia.Controls.DataGrid/Themes/Simple.xaml" />
<FluentTheme x:Key="fluentTheme" Mode="Light" />
<SimpleTheme x:Key="simpleTheme" Mode="Light" />
</Application.Resources> </Application.Resources>
</Application> </Application>

View File

@ -1,10 +1,11 @@
using System;
using Avalonia; using Avalonia;
using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml; using Avalonia.Markup.Xaml;
using Avalonia.Styling; using Avalonia.Styling;
using Avalonia.Themes.Fluent; using Avalonia.Themes.Fluent;
using Avalonia.Themes.Simple;
using AvaloniaCoreRTDemo.Interfaces; using AvaloniaCoreRTDemo.Interfaces;
using AvaloniaCoreRTDemo.Windows; using AvaloniaCoreRTDemo.Windows;
@ -12,11 +13,10 @@ namespace AvaloniaCoreRTDemo
{ {
public sealed class App : Application, IThemeSwitch public sealed class App : Application, IThemeSwitch
{ {
private IStyle _baseLight; private FluentTheme _fluentTheme;
private IStyle _baseDark; private SimpleTheme _simpleTheme;
private IStyle _fluentDataGrid;
private IStyle _fluentLight; private IStyle _simpleDataGrid;
private IStyle _fluentDark;
private ApplicationTheme _currentTheme; private ApplicationTheme _currentTheme;
@ -31,7 +31,7 @@ namespace AvaloniaCoreRTDemo
this.InitializeThemes(); this.InitializeThemes();
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{ {
desktop.MainWindow = !Utilities.IsOSX ? new MainWindow() : new MainWindowMacOS(); desktop.MainWindow = new MainWindow();
this.DataContext = desktop.MainWindow.DataContext; this.DataContext = desktop.MainWindow.DataContext;
} }
base.OnFrameworkInitializationCompleted(); base.OnFrameworkInitializationCompleted();
@ -39,45 +39,63 @@ namespace AvaloniaCoreRTDemo
private void InitializeThemes() private void InitializeThemes()
{ {
this._baseDark = this.Styles[0]; this._fluentTheme = (FluentTheme)this.Resources["fluentTheme"]!;
this._baseLight = this.Styles[1]; this._simpleTheme = (SimpleTheme)this.Resources["simpleTheme"]!;
this._fluentDataGrid = (IStyle)this.Resources["fluentDataGrid"]!;
this._simpleDataGrid = (IStyle)this.Resources["simpleDataGrid"]!;
Styles.Add(_fluentTheme);
Styles.Add(_fluentDataGrid);
this.Styles.Remove(this._baseDark); this._currentTheme = ApplicationTheme.FluentLight;
this._fluentLight = (FluentTheme)this.Resources["fluentLight"]!;
this._fluentDark = (FluentTheme)this.Resources["fluentDark"]!;
this._currentTheme = ApplicationTheme.DefaultLight;
} }
ApplicationTheme IThemeSwitch.Current => this._currentTheme; ApplicationTheme IThemeSwitch.Current => this._currentTheme;
void IThemeSwitch.ChangeTheme(ApplicationTheme theme) void IThemeSwitch.ChangeTheme(ApplicationTheme theme)
{ {
var themeChanged = theme switch
{
ApplicationTheme.SimpleLight => _currentTheme is ApplicationTheme.FluentDark or ApplicationTheme.FluentLight,
ApplicationTheme.SimpleDark => _currentTheme is ApplicationTheme.FluentDark or ApplicationTheme.FluentLight,
ApplicationTheme.FluentLight => _currentTheme is ApplicationTheme.SimpleLight or ApplicationTheme.SimpleDark,
ApplicationTheme.FluentDark => _currentTheme is ApplicationTheme.SimpleLight or ApplicationTheme.SimpleDark,
_ => throw new ArgumentOutOfRangeException(nameof(theme), theme, null)
};
this._currentTheme = theme; this._currentTheme = theme;
switch (theme) switch (theme)
{ {
case ApplicationTheme.DefaultLight: case ApplicationTheme.SimpleLight:
this.Styles[0] = this._baseLight; this._simpleTheme.Mode = SimpleThemeMode.Light;
this.Styles.Remove(this._baseDark); this.Styles[0] = this._simpleTheme;
this.Styles[1] = this._simpleDataGrid;
break; break;
case ApplicationTheme.DefaultDark: case ApplicationTheme.SimpleDark:
this.Styles[0] = this._baseDark; this._simpleTheme.Mode = SimpleThemeMode.Dark;
this.Styles.Remove(this._baseLight); this.Styles[0] = this._simpleTheme;
this.Styles[1] = this._simpleDataGrid;
break; break;
case ApplicationTheme.FluentLight: case ApplicationTheme.FluentLight:
this.Styles[0] = this._fluentLight; this._fluentTheme.Mode = FluentThemeMode.Light;
this.Styles.Remove(this._fluentDark); this.Styles[0] = this._fluentTheme;
if (!this.Styles.Contains(this._baseLight)) this.Styles[1] = this._fluentDataGrid;
this.Styles.Add(this._baseLight);
break; break;
case ApplicationTheme.FluentDark: case ApplicationTheme.FluentDark:
this.Styles[0] = this._fluentDark; this._fluentTheme.Mode = FluentThemeMode.Dark;
this.Styles.Remove(this._baseLight); this.Styles[0] = this._fluentTheme;
if (!this.Styles.Contains(this._baseDark)) this.Styles[1] = this._fluentDataGrid;
this.Styles.Add(this._baseDark);
break; break;
} }
if (themeChanged && ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
var oldWindow = desktop.MainWindow;
var newWindow = new MainWindow();
desktop.MainWindow = newWindow;
newWindow.Show();
oldWindow.Close();
this.DataContext = desktop.MainWindow.DataContext;
}
} }
} }
} }

View File

@ -4,8 +4,8 @@ namespace AvaloniaCoreRTDemo
{ {
public enum ApplicationTheme : Byte public enum ApplicationTheme : Byte
{ {
DefaultLight = 0, SimpleLight = 0,
DefaultDark = 1, SimpleDark = 1,
FluentLight = 2, FluentLight = 2,
FluentDark = 3, FluentDark = 3,
} }

View File

@ -3,16 +3,15 @@
<PropertyGroup> <PropertyGroup>
<!-- if you want to check exceptions, change this to "Exe" and start your app from the console --> <!-- if you want to check exceptions, change this to "Exe" and start your app from the console -->
<OutputType>WinExe</OutputType> <OutputType>WinExe</OutputType>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net7.0</TargetFramework>
<Platforms>x64</Platforms> <Platforms>x64</Platforms>
<ApplicationIcon>Assets/app.ico</ApplicationIcon> <ApplicationIcon>Assets/app.ico</ApplicationIcon>
<InvariantGlobalization>true</InvariantGlobalization> <InvariantGlobalization>true</InvariantGlobalization>
<!--https://docs.microsoft.com/en-us/dotnet/core/deploying/trimming/trimming-options--> <PublishAot>true</PublishAot>
<TrimmerDefaultAction>link</TrimmerDefaultAction>
<IsWindows Condition="$([MSBuild]::IsOSPlatform('Windows'))">true</IsWindows> <IsWindows Condition="$([MSBuild]::IsOSPlatform('Windows'))">true</IsWindows>
<IsLinux Condition="$([MSBuild]::IsOSPlatform('Linux'))">true</IsLinux> <IsLinux Condition="$([MSBuild]::IsOSPlatform('Linux'))">true</IsLinux>
<IsOSX Condition="$([MSBuild]::IsOSPlatform('OSX'))">true</IsOSX> <IsOSX Condition="$([MSBuild]::IsOSPlatform('OSX'))">true</IsOSX>
<DefineConstants Condition="'$(IsOSX)'=='true'">OSX</DefineConstants>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
@ -21,40 +20,40 @@
<IlcGenerateCompleteTypeMetadata>false</IlcGenerateCompleteTypeMetadata> <IlcGenerateCompleteTypeMetadata>false</IlcGenerateCompleteTypeMetadata>
<IlcGenerateStackTraceData>false</IlcGenerateStackTraceData> <IlcGenerateStackTraceData>false</IlcGenerateStackTraceData>
<IlcDisableUnhandledExceptionExperience>true</IlcDisableUnhandledExceptionExperience> <IlcDisableUnhandledExceptionExperience>true</IlcDisableUnhandledExceptionExperience>
<StripSymbols>true</StripSymbols>
</PropertyGroup> </PropertyGroup>
<!-- Instruct NativeAOT to use this native dependency, required to build Avalonia. This library comes from the Windows SDK. -->
<ItemGroup Condition="'$(IsWindows)'=='true'">
<NativeLibrary Include="WindowsApp.lib" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<AvaloniaResource Include="Assets/**" /> <AvaloniaResource Include="Assets/**" />
<EmbeddedResource Include="Images/**" /> <AvaloniaResource Include="Images/**" />
<None Update="avalonia.png" CopyToPublishDirectory="PreserveNewest">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="dotnet.png" CopyToPublishDirectory="PreserveNewest">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Assets/app.icns" CopyToPublishDirectory="PreserveNewest" Condition="$(RuntimeIdentifier.StartsWith('osx'))"> <None Update="Assets/app.icns" CopyToPublishDirectory="PreserveNewest" Condition="$(RuntimeIdentifier.StartsWith('osx'))">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Update="dotnet.png">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="avalonia.png">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Avalonia" Version="0.10.18" /> <PackageReference Include="Avalonia" Version="11.0.999-cibuild0026389-beta" />
<PackageReference Include="Avalonia.Desktop" Version="0.10.18" /> <PackageReference Include="Avalonia.Desktop" Version="11.0.999-cibuild0026389-beta" />
<PackageReference Include="Avalonia.Native" Version="0.10.18" /> <PackageReference Include="Avalonia.Controls.DataGrid" Version="11.0.999-cibuild0026389-beta" />
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.18" /> <PackageReference Include="Avalonia.ReactiveUI" Version="11.0.999-cibuild0026389-beta" />
<PackageReference Include="Avalonia.Themes.Simple" Version="11.0.999-cibuild0026389-beta" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.999-cibuild0026389-beta" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.--> <!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="0.10.18" /> <PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.999-cibuild0026389-beta" />
<!--Condition below is needed to generate macOS App only.--> <!--Condition below is needed to generate macOS App only.-->
<PackageReference Include="Dotnet.Bundle" Version="*" Condition="$(RuntimeIdentifier.StartsWith('osx'))" /> <PackageReference Include="Dotnet.Bundle" Version="*" Condition="$(RuntimeIdentifier.StartsWith('osx'))" />
</ItemGroup> </ItemGroup>
<!-- Information for Dotnet.Bundle to Generate macOS app--> <!-- Information for Dotnet.Bundle to Generate macOS app-->
<PropertyGroup Condition="'$(IsOSX)'=='true'"> <PropertyGroup>
<CFBundleName>$(AssemblyName)</CFBundleName> <CFBundleName>$(AssemblyName)</CFBundleName>
<CFBundleDisplayName>$(AssemblyName)</CFBundleDisplayName> <CFBundleDisplayName>$(AssemblyName)</CFBundleDisplayName>
<CFBundleIdentifier>com.$(username).$(AssemblyName)</CFBundleIdentifier> <CFBundleIdentifier>com.$(username).$(AssemblyName)</CFBundleIdentifier>
@ -70,39 +69,4 @@
<NSRequiresAquaSystemAppearance>true</NSRequiresAquaSystemAppearance> <NSRequiresAquaSystemAppearance>true</NSRequiresAquaSystemAppearance>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.DotNet.ILCompiler" Version="8.0.0-*" />
<!-- Avalonia relies heavily on reflection. Describe types reflected upon here. -->
<RdXmlFile Include="rd.xml" />
<RuntimeHostConfigurationOption Include="Switch.System.Reflection.Assembly.SimulatedCallingAssembly" Value="true" />
</ItemGroup>
<!--App axaml-->
<ItemGroup>
<Compile Update="App.axaml.cs">
<DependentUpon>App.axaml</DependentUpon>
</Compile>
</ItemGroup>
<!--Cross platform xaml-->
<ItemGroup>
<Compile Update="Controls/MainControl.axaml.cs">
<DependentUpon>MainControl.axaml</DependentUpon>
</Compile>
<Compile Update="Windows/AboutWindow.axaml.cs">
<DependentUpon>AboutWindow.axaml</DependentUpon>
</Compile>
</ItemGroup>
<!--No-OSX only xaml-->
<ItemGroup Condition="'$(IsOSX)'!='true'">
<Compile Update="Windows/MainWindow.axaml.cs">
<DependentUpon>MainWindow.axaml</DependentUpon>
</Compile>
</ItemGroup>
<!--OSX only xaml-->
<ItemGroup Condition="'$(IsOSX)'=='true'">
<Compile Update="Windows/MainWindowMacOS.axaml.cs">
<DependentUpon>MainWindowMacOS.axaml</DependentUpon>
</Compile>
</ItemGroup>
</Project> </Project>

View File

@ -1,5 +1,8 @@
<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" <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="800" d:DesignHeight="450" x:Class="AvaloniaCoreRTDemo.Controls.MainControl"> xmlns:viewModels="clr-namespace:AvaloniaCoreRTDemo.Controls.ViewModels"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="AvaloniaCoreRTDemo.Controls.MainControl"
x:CompileBindings="True"
x:DataType="viewModels:MainViewModel">
<Grid ColumnDefinitions="*,*" RowDefinitions="Auto,Auto,*" Margin="32"> <Grid ColumnDefinitions="*,*" RowDefinitions="Auto,Auto,*" Margin="32">
<TextBlock Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" TextAlignment="Center" Margin="0,6">Welcome to Avalonia UI + NativeAOT!</TextBlock> <TextBlock Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" TextAlignment="Center" Margin="0,6">Welcome to Avalonia UI + NativeAOT!</TextBlock>
<Image Grid.Row="1" Grid.Column="0" Stretch="None" Source="{Binding DotNetImage}"/> <Image Grid.Row="1" Grid.Column="0" Stretch="None" Source="{Binding DotNetImage}"/>

View File

@ -18,13 +18,10 @@ namespace AvaloniaCoreRTDemo.Controls.ViewModels
public MainViewModel() public MainViewModel()
{ {
this._dotNetImage = Utilities.GetImageFromFile(GetImageFullPath("dotnet.png")); this._dotNetImage = Utilities.GetImageFromFile("dotnet.png");
this._avaloniaImage = Utilities.GetImageFromFile(GetImageFullPath("avalonia.png")); this._avaloniaImage = Utilities.GetImageFromFile("avalonia.png");
} }
private static String GetImageFullPath(String fileName)
=> Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName);
~MainViewModel() ~MainViewModel()
{ {
this._dotNetImage.Dispose(); this._dotNetImage.Dispose();

View File

@ -12,10 +12,6 @@ namespace AvaloniaCoreRTDemo
// Avalonia configuration, don't remove; also used by visual designer. // Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp() public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>().UsePlatformDetect() => AppBuilder.Configure<App>().UsePlatformDetect()
.UseAvaloniaNativeOSX()
.LogToTrace(); .LogToTrace();
private static AppBuilder UseAvaloniaNativeOSX(this AppBuilder appBuilder)
=> Utilities.IsOSX ? appBuilder.UseAvaloniaNative() : appBuilder;
} }
} }

View File

@ -1,10 +1,9 @@
using System; using System;
using System.IO; using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Avalonia;
using Avalonia.Media.Imaging; using Avalonia.Media.Imaging;
using Avalonia.Platform;
namespace AvaloniaCoreRTDemo namespace AvaloniaCoreRTDemo
{ {
@ -15,25 +14,24 @@ namespace AvaloniaCoreRTDemo
public static Bitmap GetImageFromResources(String fileName) public static Bitmap GetImageFromResources(String fileName)
{ {
Assembly asm = Assembly.GetExecutingAssembly(); var assetLoader = AvaloniaLocator.Current.GetRequiredService<IAssetLoader>();
String resourceName = asm.GetManifestResourceNames().FirstOrDefault(str => str.EndsWith(fileName)); using var assetStream = assetLoader.Open(new Uri($"avares://AvaloniaCoreRTDemo/Images/{fileName}"));
if (resourceName != null) return new Bitmap(assetStream);
using (Stream bitmapStream = asm.GetManifestResourceStream(resourceName))
return new Bitmap(bitmapStream);
else
return default;
} }
public static Bitmap GetImageFromFile(String path) public static Bitmap GetImageFromFile(String path)
{ {
try try
{ {
return new Bitmap(path); return new Bitmap(GetImageFullPath(path));
} }
catch (Exception) catch (Exception)
{ {
return GetImageFromResources("broken-link.png"); return GetImageFromResources("broken-link.png");
} }
} }
private static String GetImageFullPath(String fileName)
=> Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName);
} }
} }

View File

@ -1,64 +1,20 @@
<Window 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" <Window 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" x:Class="AvaloniaCoreRTDemo.Windows.AboutWindow" d:DesignWidth="640" d:DesignHeight="256" xmlns:viewModels="clr-namespace:AvaloniaCoreRTDemo.Windows.ViewModels"
WindowState="Normal" WindowStartupLocation="CenterOwner" MinHeight="256" MinWidth="640" Height="256" Width="640" MaxHeight="256" MaxWidth="640" Title="About" CanResize="false" ShowInTaskbar="False" Icon="avares://AvaloniaCoreRTDemo/Assets/about.ico"> mc:Ignorable="d" x:Class="AvaloniaCoreRTDemo.Windows.AboutWindow" d:DesignWidth="640" d:DesignHeight="256"
<Grid VerticalAlignment="Top" HorizontalAlignment="Left" ColumnDefinitions="Auto,Auto" RowDefinitions="Auto"> WindowState="Normal" WindowStartupLocation="CenterOwner" Height="256" MaxWidth="840"
<Image Margin="0, 60" Grid.Row="0" Grid.Column="0" Stretch="None" Source="{Binding ComputerImage}" VerticalAlignment="Top" HorizontalAlignment="Left"> SizeToContent="Width"
</Image> Title="About"
<ScrollViewer Margin="0, 10" Width="500" Height="230" Grid.Row="0" Grid.Column="1" VerticalAlignment="Top" HorizontalAlignment="Left" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Auto"> CanResize="false" ShowInTaskbar="False" Icon="avares://AvaloniaCoreRTDemo/Assets/about.ico"
<Grid ColumnDefinitions="Auto" RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto"> x:CompileBindings="True"
<Grid Grid.Row="0" Grid.Column="0" ColumnDefinitions="Auto,Auto" RowDefinitions="Auto"> x:DataType="viewModels:AboutViewModel">
<TextBlock Grid.Row="0" Grid.Column="0" VerticalAlignment="Top" HorizontalAlignment="Left" TextAlignment="Left" FontWeight="Bold" Text="Number of Cores: "/> <Grid VerticalAlignment="Top" HorizontalAlignment="Left" ColumnDefinitions="Auto,*">
<TextBlock Grid.Row="0" Grid.Column="1" VerticalAlignment="Top" HorizontalAlignment="Left" TextAlignment="Left" Text="{Binding NCores}"/> <Image Margin="0, 60" Grid.Column="0" Stretch="None" Source="{Binding ComputerImage}" VerticalAlignment="Top" HorizontalAlignment="Left">
</Grid> </Image>
<Grid Grid.Row="1" Grid.Column="0" ColumnDefinitions="Auto,Auto" RowDefinitions="Auto"> <DataGrid Grid.Column="1" Items="{Binding SystemDetails}" IsReadOnly="True">
<TextBlock Grid.Row="0" Grid.Column="0" VerticalAlignment="Top" HorizontalAlignment="Left" TextAlignment="Left" FontWeight="Bold" Text="OS: "/> <DataGrid.Columns>
<TextBlock Grid.Row="0" Grid.Column="1" VerticalAlignment="Top" HorizontalAlignment="Left" TextAlignment="Left" Text="{Binding OS}"/> <DataGridTextColumn Header="Key" Binding="{Binding Key, x:DataType=viewModels:SystemDetail}" FontWeight="Bold" />
</Grid> <DataGridTextColumn Header="Value" Binding="{Binding Value, x:DataType=viewModels:SystemDetail}" />
<Grid Grid.Row="2" Grid.Column="0" ColumnDefinitions="Auto,Auto" RowDefinitions="Auto"> </DataGrid.Columns>
<TextBlock Grid.Row="0" Grid.Column="0" VerticalAlignment="Top" HorizontalAlignment="Left" TextAlignment="Left" FontWeight="Bold" Text="OS Arch: "/> </DataGrid>
<TextBlock Grid.Row="0" Grid.Column="1" VerticalAlignment="Top" HorizontalAlignment="Left" TextAlignment="Left" Text="{Binding OSArch}"/>
</Grid>
<Grid Grid.Row="3" Grid.Column="0" ColumnDefinitions="Auto,Auto" RowDefinitions="Auto">
<TextBlock Grid.Row="0" Grid.Column="0" VerticalAlignment="Top" HorizontalAlignment="Left" TextAlignment="Left" FontWeight="Bold" Text="OS Version: "/>
<TextBlock Grid.Row="0" Grid.Column="1" VerticalAlignment="Top" HorizontalAlignment="Left" TextAlignment="Left" Text="{Binding OSVersion}"/>
</Grid>
<Grid Grid.Row="4" Grid.Column="0" ColumnDefinitions="Auto,Auto" RowDefinitions="Auto">
<TextBlock Grid.Row="0" Grid.Column="0" VerticalAlignment="Top" HorizontalAlignment="Left" TextAlignment="Left" FontWeight="Bold" Text="Computer: "/>
<TextBlock Grid.Row="0" Grid.Column="1" VerticalAlignment="Top" HorizontalAlignment="Left" TextAlignment="Left" Text="{Binding ComputerName}"/>
</Grid>
<Grid Grid.Row="5" Grid.Column="0" ColumnDefinitions="Auto,Auto" RowDefinitions="Auto">
<TextBlock Grid.Row="0" Grid.Column="0" VerticalAlignment="Top" HorizontalAlignment="Left" TextAlignment="Left" FontWeight="Bold" Text="User: "/>
<TextBlock Grid.Row="0" Grid.Column="1" VerticalAlignment="Top" HorizontalAlignment="Left" TextAlignment="Left" Text="{Binding UserName}"/>
</Grid>
<Grid Grid.Row="6" Grid.Column="0" ColumnDefinitions="Auto,Auto" RowDefinitions="Auto">
<TextBlock Grid.Row="0" Grid.Column="0" VerticalAlignment="Top" HorizontalAlignment="Left" TextAlignment="Left" FontWeight="Bold" Text="System Path: "/>
<TextBlock Grid.Row="0" Grid.Column="1" VerticalAlignment="Top" HorizontalAlignment="Left" TextAlignment="Left" Text="{Binding SystemPath}"/>
</Grid>
<Grid Grid.Row="7" Grid.Column="0" ColumnDefinitions="Auto,Auto" RowDefinitions="Auto">
<TextBlock Grid.Row="0" Grid.Column="0" VerticalAlignment="Top" HorizontalAlignment="Left" TextAlignment="Left" FontWeight="Bold" Text="Current Path: "/>
<TextBlock Grid.Row="0" Grid.Column="1" VerticalAlignment="Top" HorizontalAlignment="Left" TextAlignment="Left" Text="{Binding CurrentPath}"/>
</Grid>
<Grid Grid.Row="8" Grid.Column="0" ColumnDefinitions="Auto,Auto" RowDefinitions="Auto">
<TextBlock Grid.Row="0" Grid.Column="0" VerticalAlignment="Top" HorizontalAlignment="Left" TextAlignment="Left" FontWeight="Bold" Text="Process Arch: "/>
<TextBlock Grid.Row="0" Grid.Column="1" VerticalAlignment="Top" HorizontalAlignment="Left" TextAlignment="Left" Text="{Binding ProcessArch}"/>
</Grid>
<Grid Grid.Row="9" Grid.Column="0" ColumnDefinitions="Auto,Auto" RowDefinitions="Auto">
<TextBlock Grid.Row="0" Grid.Column="0" VerticalAlignment="Top" HorizontalAlignment="Left" TextAlignment="Left" FontWeight="Bold" Text="Runtime Name: "/>
<TextBlock Grid.Row="0" Grid.Column="1" VerticalAlignment="Top" HorizontalAlignment="Left" TextAlignment="Left" Text="{Binding RuntimeName}"/>
</Grid>
<Grid Grid.Row="10" Grid.Column="0" ColumnDefinitions="Auto,Auto" RowDefinitions="Auto">
<TextBlock Grid.Row="0" Grid.Column="0" VerticalAlignment="Top" HorizontalAlignment="Left" TextAlignment="Left" FontWeight="Bold" Text="Runtime Path: "/>
<TextBlock Grid.Row="0" Grid.Column="1" VerticalAlignment="Top" HorizontalAlignment="Left" TextAlignment="Left" Text="{Binding RuntimePath}"/>
</Grid>
<Grid Grid.Row="11" Grid.Column="0" ColumnDefinitions="Auto,Auto" RowDefinitions="Auto">
<TextBlock Grid.Row="0" Grid.Column="0" VerticalAlignment="Top" HorizontalAlignment="Left" TextAlignment="Left" FontWeight="Bold" Text="Runtime Version: "/>
<TextBlock Grid.Row="0" Grid.Column="1" VerticalAlignment="Top" HorizontalAlignment="Left" TextAlignment="Left" Text="{Binding RuntimeVersion}"/>
</Grid>
<Grid Grid.Row="12" Grid.Column="0" ColumnDefinitions="Auto,Auto" RowDefinitions="Auto">
<TextBlock Grid.Row="0" Grid.Column="0" VerticalAlignment="Top" HorizontalAlignment="Left" TextAlignment="Left" FontWeight="Bold" Text="Framework Version: "/>
<TextBlock Grid.Row="0" Grid.Column="1" VerticalAlignment="Top" HorizontalAlignment="Left" TextAlignment="Left" Text="{Binding FrameworkVersion}"/>
</Grid>
</Grid>
</ScrollViewer>
</Grid> </Grid>
</Window> </Window>

View File

@ -1,21 +1,34 @@
<Window 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" <Window 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:controls="clr-namespace:AvaloniaCoreRTDemo.Controls" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="AvaloniaCoreRTDemo.Windows.MainWindow" xmlns:controls="clr-namespace:AvaloniaCoreRTDemo.Controls"
Width="640" Height="480" WindowStartupLocation="CenterScreen" Title="AvaloniaCoreRTDemo" Icon="avares://AvaloniaCoreRTDemo/Assets/app.ico" MinWidth="400" MinHeight="350"> xmlns:viewModels1="clr-namespace:AvaloniaCoreRTDemo.Windows.ViewModels"
<DockPanel> mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="AvaloniaCoreRTDemo.Windows.MainWindow"
<Menu DockPanel.Dock="Top"> Width="640" Height="480" WindowStartupLocation="CenterScreen" Title="AvaloniaCoreRTDemo" Icon="avares://AvaloniaCoreRTDemo/Assets/app.ico" MinWidth="400" MinHeight="350"
<MenuItem Header="_File"> x:CompileBindings="True"
<MenuItem Header="_Exit" Command="{Binding FileExitCommand}"/> x:DataType="viewModels1:MainViewModelBase">
</MenuItem> <DockPanel>
<MenuItem Header="_Theme"> <NativeMenuBar DockPanel.Dock="Top" />
<MenuItem Header="Default Light" IsEnabled="{Binding DefaultLightEnabled}" Command="{Binding DefaultLightMethod}"/> <controls:MainControl/>
<MenuItem Header="Default Dark" IsEnabled="{Binding DefaultDarkEnabled}" Command="{Binding DefaultDarkMethod}"/> </DockPanel>
<MenuItem Header="Fluent Light" IsEnabled="{Binding FluentLightEnabled}" Command="{Binding FluentLightMethod}"/> <NativeMenu.Menu>
<MenuItem Header="Fluent Dark" IsEnabled="{Binding FluentDarkEnabled}" Command="{Binding FluentDarkMethod}"/> <NativeMenu>
</MenuItem> <NativeMenuItem Header="File">
<MenuItem Header="_Help"> <NativeMenuItem.Menu>
<MenuItem Header="_About" IsEnabled="{Binding AboutEnabled}" Command="{Binding HelpAboutMethod}"/> <NativeMenu>
</MenuItem> <NativeMenuItem Header="Exit" Gesture="cmd+e" Command="{Binding FileExitCommand}"/>
</Menu> <NativeMenuItem Header="About" Gesture="cmd+b" IsEnabled="{Binding AboutEnabled}" Command="{Binding HelpAboutMethod}"/>
<controls:MainControl/> </NativeMenu>
</DockPanel> </NativeMenuItem.Menu>
</NativeMenuItem>
<NativeMenuItem Header="Theme">
<NativeMenuItem.Menu>
<NativeMenu>
<NativeMenuItem Header="Default Light" IsEnabled="{Binding DefaultLightEnabled}" Command="{Binding DefaultLightMethod}"/>
<NativeMenuItem Header="Default Dark" IsEnabled="{Binding DefaultDarkEnabled}" Command="{Binding DefaultDarkMethod}"/>
<NativeMenuItem Header="Fluent Light" IsEnabled="{Binding FluentLightEnabled}" Command="{Binding FluentLightMethod}"/>
<NativeMenuItem Header="Fluent Dark" IsEnabled="{Binding FluentDarkEnabled}" Command="{Binding FluentDarkMethod}"/>
</NativeMenu>
</NativeMenuItem.Menu>
</NativeMenuItem>
</NativeMenu>
</NativeMenu.Menu>
</Window> </Window>

View File

@ -1,26 +0,0 @@
<Window 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:controls="clr-namespace:AvaloniaCoreRTDemo.Controls" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="AvaloniaCoreRTDemo.Windows.MainWindowMacOS"
Width="640" Height="480" WindowStartupLocation="CenterScreen" Title="AvaloniaCoreRTDemo" Icon="avares://AvaloniaCoreRTDemo/Assets/app.ico" MinWidth="400" MinHeight="350">
<controls:MainControl/>
<NativeMenu.Menu>
<NativeMenu>
<NativeMenuItem Header="File">
<NativeMenuItem.Menu>
<NativeMenu>
<NativeMenuItem Header="Exit" Gesture="cmd+e" Command="{Binding FileExitCommand}"/>
</NativeMenu>
</NativeMenuItem.Menu>
</NativeMenuItem>
<NativeMenuItem Header="Theme">
<NativeMenuItem.Menu>
<NativeMenu>
<NativeMenuItem Header="Default Light" IsEnabled="{Binding DefaultLightEnabled}" Command="{Binding DefaultLightMethod}"/>
<NativeMenuItem Header="Default Dark" IsEnabled="{Binding DefaultDarkEnabled}" Command="{Binding DefaultDarkMethod}"/>
<NativeMenuItem Header="Fluent Light" IsEnabled="{Binding FluentLightEnabled}" Command="{Binding FluentLightMethod}"/>
<NativeMenuItem Header="Fluent Dark" IsEnabled="{Binding FluentDarkEnabled}" Command="{Binding FluentDarkMethod}"/>
</NativeMenu>
</NativeMenuItem.Menu>
</NativeMenuItem>
</NativeMenu>
</NativeMenu.Menu>
</Window>

View File

@ -1,28 +0,0 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using AvaloniaCoreRTDemo.Interfaces;
using AvaloniaCoreRTDemo.Windows.ViewModels;
namespace AvaloniaCoreRTDemo.Windows
{
public partial class MainWindowMacOS : Window, IMainWindow
{
public MainWindowMacOS()
{
InitializeComponent();
#if DEBUG
this.AttachDevTools();
#endif
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
this.DataContext = new MainViewModel<MainWindowMacOS>(this);
}
IThemeSwitch IMainWindow.ThemeSwitch => App.Current as IThemeSwitch;
}
}

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Avalonia.Media.Imaging; using Avalonia.Media.Imaging;
@ -7,25 +8,32 @@ using ReactiveUI;
namespace AvaloniaCoreRTDemo.Windows.ViewModels namespace AvaloniaCoreRTDemo.Windows.ViewModels
{ {
internal record SystemDetail(string Key, string Value);
internal sealed class AboutViewModel : ReactiveObject internal sealed class AboutViewModel : ReactiveObject
{ {
private readonly IBitmap _computerImage; private readonly IBitmap _computerImage;
private readonly Boolean _darkTheme; private readonly Boolean _darkTheme;
public IBitmap ComputerImage => _computerImage; public IBitmap ComputerImage => _computerImage;
public static String NCores => Environment.ProcessorCount.ToString();
public static String OS => RuntimeInformation.OSDescription; public IReadOnlyList<SystemDetail> SystemDetails { get; } = new[]
public static String OSArch => RuntimeInformation.OSArchitecture.ToString(); {
public static String OSVersion => Environment.OSVersion.ToString(); new SystemDetail("Number of Cores", Environment.ProcessorCount.ToString()),
public static String ComputerName => Environment.MachineName; new SystemDetail("OS", RuntimeInformation.OSDescription),
public static String UserName => Environment.UserName; new SystemDetail("OS Arch", RuntimeInformation.OSArchitecture.ToString()),
public static String SystemPath => Environment.SystemDirectory; new SystemDetail("OS Version", Environment.OSVersion.ToString()),
public static String CurrentPath => Environment.CurrentDirectory; new SystemDetail("Computer", Environment.MachineName),
public static String ProcessArch => RuntimeInformation.ProcessArchitecture.ToString(); new SystemDetail("User", Environment.UserName),
public static String RuntimeName => RuntimeInformation.FrameworkDescription; new SystemDetail("System Path", Environment.SystemDirectory),
public static String RuntimePath => RuntimeEnvironment.GetRuntimeDirectory(); new SystemDetail("Current Path", Environment.CurrentDirectory),
public static String RuntimeVersion => RuntimeEnvironment.GetSystemVersion(); new SystemDetail("Process Arch", RuntimeInformation.ProcessArchitecture.ToString()),
public static String FrameworkVersion => Environment.Version.ToString(); new SystemDetail("Runtime Name", RuntimeInformation.FrameworkDescription),
new SystemDetail("Runtime Path", RuntimeEnvironment.GetRuntimeDirectory()),
new SystemDetail("Runtime Version", RuntimeEnvironment.GetSystemVersion()),
new SystemDetail("Framework Version", Environment.Version.ToString()),
};
private String ComputerImageName private String ComputerImageName
{ {

View File

@ -12,58 +12,25 @@ namespace AvaloniaCoreRTDemo.Windows.ViewModels
{ {
private readonly TWindow _window; private readonly TWindow _window;
private Boolean _defaultLightEnable = true;
private Boolean _defaultDarkEnable = true;
private Boolean _fluentLightEnable = true;
private Boolean _fluentDarkEnable = true;
public Boolean DefaultLightEnabled
{
get => this._defaultLightEnable;
set => this.RaiseAndSetIfChanged(ref this._defaultLightEnable, value);
}
public Boolean DefaultDarkEnabled
{
get => this._defaultDarkEnable;
set => this.RaiseAndSetIfChanged(ref this._defaultDarkEnable, value);
}
public Boolean FluentLightEnabled
{
get => this._fluentLightEnable;
set => this.RaiseAndSetIfChanged(ref this._fluentLightEnable, value);
}
public Boolean FluentDarkEnabled
{
get => this._fluentDarkEnable;
set => this.RaiseAndSetIfChanged(ref this._fluentDarkEnable, value);
}
public ReactiveCommand<Unit, Unit> FileExitCommand { get; }
public MainViewModel(TWindow window) public MainViewModel(TWindow window)
: base(window.ThemeSwitch) : base(window.ThemeSwitch)
{ {
this._window = window; this._window = window;
this.FileExitCommand = ReactiveCommand.Create(RunFileExit);
this.ChangeTheme(window.ThemeSwitch.Current); this.ChangeTheme(window.ThemeSwitch.Current);
} }
public void DefaultLightMethod() => this.ChangeTheme(ApplicationTheme.DefaultLight);
public void DefaultDarkMethod() => this.ChangeTheme(ApplicationTheme.DefaultDark);
public void FluentLightMethod() => this.ChangeTheme(ApplicationTheme.FluentLight);
public void FluentDarkMethod() => this.ChangeTheme(ApplicationTheme.FluentDark);
public override void HelpAboutMethod() => base.RunHelpAbout(this._window); public override void HelpAboutMethod() => base.RunHelpAbout(this._window);
private void RunFileExit() public override void DefaultLightMethod() => this.ChangeTheme(ApplicationTheme.SimpleLight);
=> Environment.Exit(0); public override void DefaultDarkMethod() => this.ChangeTheme(ApplicationTheme.SimpleDark);
public override void FluentLightMethod() => this.ChangeTheme(ApplicationTheme.FluentLight);
public override void FluentDarkMethod() => this.ChangeTheme(ApplicationTheme.FluentDark);
private void ChangeTheme(ApplicationTheme theme) private void ChangeTheme(ApplicationTheme theme)
{ {
this.DefaultLightEnabled = theme != ApplicationTheme.DefaultLight && theme != ApplicationTheme.FluentLight; this.DefaultLightEnabled = theme != ApplicationTheme.SimpleLight;
this.DefaultDarkEnabled = theme != ApplicationTheme.DefaultDark && theme != ApplicationTheme.FluentDark; this.DefaultDarkEnabled = theme != ApplicationTheme.SimpleDark;
this.FluentLightEnabled = theme != ApplicationTheme.FluentLight; this.FluentLightEnabled = theme != ApplicationTheme.FluentLight;
this.FluentDarkEnabled = theme != ApplicationTheme.FluentDark; this.FluentDarkEnabled = theme != ApplicationTheme.FluentDark;
this._window.ThemeSwitch?.ChangeTheme(theme); this._window.ThemeSwitch?.ChangeTheme(theme);

View File

@ -1,5 +1,5 @@
using System; using System;
using System.Reactive;
using Avalonia.Controls; using Avalonia.Controls;
using AvaloniaCoreRTDemo.Interfaces; using AvaloniaCoreRTDemo.Interfaces;
@ -12,6 +12,10 @@ namespace AvaloniaCoreRTDemo.Windows.ViewModels
{ {
private readonly IThemeSwitch _themeSwitch; private readonly IThemeSwitch _themeSwitch;
private Boolean _aboutEnable = true; private Boolean _aboutEnable = true;
private Boolean _defaultLightEnable = true;
private Boolean _defaultDarkEnable = true;
private Boolean _fluentLightEnable = true;
private Boolean _fluentDarkEnable = true;
public Boolean AboutEnabled public Boolean AboutEnabled
{ {
@ -20,10 +24,47 @@ namespace AvaloniaCoreRTDemo.Windows.ViewModels
} }
public MainViewModelBase(IThemeSwitch window) public MainViewModelBase(IThemeSwitch window)
=> this._themeSwitch = window; {
this._themeSwitch = window;
this.FileExitCommand = ReactiveCommand.Create(RunFileExit);
}
public Boolean DefaultLightEnabled
{
get => this._defaultLightEnable;
set => this.RaiseAndSetIfChanged(ref this._defaultLightEnable, value);
}
public Boolean DefaultDarkEnabled
{
get => this._defaultDarkEnable;
set => this.RaiseAndSetIfChanged(ref this._defaultDarkEnable, value);
}
public Boolean FluentLightEnabled
{
get => this._fluentLightEnable;
set => this.RaiseAndSetIfChanged(ref this._fluentLightEnable, value);
}
public Boolean FluentDarkEnabled
{
get => this._fluentDarkEnable;
set => this.RaiseAndSetIfChanged(ref this._fluentDarkEnable, value);
}
public ReactiveCommand<Unit, Unit> FileExitCommand { get; }
public abstract void HelpAboutMethod(); public abstract void HelpAboutMethod();
public abstract void DefaultLightMethod();
public abstract void DefaultDarkMethod();
public abstract void FluentLightMethod();
public abstract void FluentDarkMethod();
private void RunFileExit()
=> Environment.Exit(0);
protected async void RunHelpAbout(Window currentWindow) protected async void RunHelpAbout(Window currentWindow)
{ {
if (this.AboutEnabled) if (this.AboutEnabled)
@ -41,7 +82,7 @@ namespace AvaloniaCoreRTDemo.Windows.ViewModels
private static Boolean IsDarkTheme(ApplicationTheme? theme) private static Boolean IsDarkTheme(ApplicationTheme? theme)
=> theme switch => theme switch
{ {
ApplicationTheme.DefaultDark => true, ApplicationTheme.SimpleDark => true,
ApplicationTheme.FluentDark => true, ApplicationTheme.FluentDark => true,
_ => false, _ => false,
}; };

View File

@ -1,8 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<configuration> <configuration>
<packageSources> <packageSources>
<add key="dotnet7" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json" /> <add key="avalonia" value="https://nuget.avaloniaui.net/repository/avalonia-all/index.json" />
<add key="dotnet8" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet8/nuget/v3/index.json" />
<add key="nuget" value="https://api.nuget.org/v3/index.json" /> <add key="nuget" value="https://api.nuget.org/v3/index.json" />
</packageSources> </packageSources>
</configuration> </configuration>

View File

@ -1,48 +0,0 @@
<Directives>
<Application>
<!-- main app assembly provides types which needs to be reflected upon -->
<Assembly Name="AvaloniaCoreRTDemo" Dynamic="Required All"></Assembly>
<!-- these are needed when you show images and draw text -->
<Assembly Name="Avalonia.Animation">
<Type Name="Avalonia.Animation.Easings.QuadraticEaseIn" Dynamic="Required All" />
<Type Name="Avalonia.Animation.Easings.QuadraticEaseOut" Dynamic="Required All" />
<Type Name="Avalonia.Animation.Easings.CubicEaseOut" Dynamic="Required All" />
<Type Name="Avalonia.Animation.Easings.LinearEasing" Dynamic="Required All" />
</Assembly>
<Assembly Name="Avalonia.Themes.Default" Dynamic="Required All"></Assembly>
<Assembly Name="Avalonia.Visuals" Dynamic="Required All">
<Type Name="Avalonia.Media.SolidColorBrush" Dynamic="Required All" />
</Assembly>
<Assembly Name="SkiaSharp" Dynamic="Required All"></Assembly>
<!-- To support Fluent themes trimming the final assembly we need to add this entry -->
<Assembly Name="Avalonia.Themes.Fluent" Dynamic="Required All"></Assembly>
<!-- Not known if and when you need these:
<Assembly Name="Avalonia.Controls" Dynamic="Required All"></Assembly>
<Assembly Name="Avalonia.Base" Dynamic="Required All"></Assembly>
<Assembly Name="Avalonia" Dynamic="Required All"></Assembly>
<Assembly Name="Avalonia.Interactivity" Dynamic="Required All"></Assembly>
<Assembly Name="Avalonia.Layout" Dynamic="Required All"></Assembly>
<Assembly Name="Avalonia.Markup" Dynamic="Required All"></Assembly>
<Assembly Name="Avalonia.Markup.Xaml" Dynamic="Required All"></Assembly>
<Assembly Name="Avalonia.Styling" Dynamic="Required All"></Assembly>
<Assembly Name="Avalonia.DesktopRuntime" Dynamic="Required All"></Assembly>
<Assembly Name="Avalonia.DesignerSupport" Dynamic="Required All"></Assembly>
<Assembly Name="Avalonia.Diagnostics" Dynamic="Required All"></Assembly>
<Assembly Name="Avalonia.Dialogs" Dynamic="Required All"></Assembly>
<Assembly Name="Avalonia.Input" Dynamic="Required All"></Assembly>
<Assembly Name="Avalonia.Logging.Serilog" Dynamic="Required All"></Assembly>
<Assembly Name="Avalonia.OpenGL" Dynamic="Required All"></Assembly>
<Assembly Name="Avalonia.Desktop" Dynamic="Required All"></Assembly>
<Assembly Name="Avalonia.Direct2D1" Dynamic="Required All"></Assembly>
<Assembly Name="Avalonia.ReactiveUI" Dynamic="Required All"></Assembly>
<Assembly Name="Avalonia.Skia" Dynamic="Required All"></Assembly>
<Assembly Name="Avalonia.Win32" Dynamic="Required All"></Assembly>
<Assembly Name="ReactiveUI" Dynamic="Required All"></Assembly>
<Assembly Name="System.Reactive" Dynamic="Required All"></Assembly>
<Assembly Name="Splat" Dynamic="Required All"></Assembly>
-->
</Application>
</Directives>

View File

@ -5,9 +5,9 @@ if [ -d "$dir" ]; then
fi fi
rm -f src/packages.lock.json rm -f src/packages.lock.json
dotnet publish -r osx-x64 -c release /p:RestoreLockedMode=true -t:BundleApp /p:TrimLink=true --self-contained dotnet publish -r osx-x64 -c release /p:RestoreLockedMode=true -t:BundleApp /p:TrimLink=true --self-contained
rm -rf src/bin/x64/Release/net6.0/osx-x64/publish/Assets/ rm -rf src/bin/x64/Release/net7.0/osx-x64/publish/Assets/
strip src/bin/x64/Release/net6.0/osx-x64/publish/AvaloniaCoreRTDemo.app/Contents/MacOS/AvaloniaCoreRTDemo strip src/bin/x64/Release/net7.0/osx-x64/publish/AvaloniaCoreRTDemo.app/Contents/MacOS/AvaloniaCoreRTDemo
rm -rf src/bin/x64/Release/net6.0/osx-x64/publish/AvaloniaCoreRTDemo.app/Contents/MacOS/Assets/ rm -rf src/bin/x64/Release/net7.0/osx-x64/publish/AvaloniaCoreRTDemo.app/Contents/MacOS/Assets/
rm src/bin/x64/Release/net6.0/osx-x64/publish/AvaloniaCoreRTDemo.app/Contents/MacOS/AvaloniaCoreRTDemo.runtimeconfig.json rm src/bin/x64/Release/net7.0/osx-x64/publish/AvaloniaCoreRTDemo.app/Contents/MacOS/AvaloniaCoreRTDemo.runtimeconfig.json
rm src/bin/x64/Release/net6.0/osx-x64/publish/AvaloniaCoreRTDemo.app/Contents/MacOS/AvaloniaCoreRTDemo.pdb rm src/bin/x64/Release/net7.0/osx-x64/publish/AvaloniaCoreRTDemo.app/Contents/MacOS/AvaloniaCoreRTDemo.pdb
rm src/bin/x64/Release/net6.0/osx-x64/publish/AvaloniaCoreRTDemo.app/Contents/MacOS/AvaloniaCoreRTDemo.deps.json rm src/bin/x64/Release/net7.0/osx-x64/publish/AvaloniaCoreRTDemo.app/Contents/MacOS/AvaloniaCoreRTDemo.deps.json

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
rm -f src/packages.lock.json rm -f src/packages.lock.json
dotnet publish -r linux-x64 -c release /p:RestoreLockedMode=true /p:TrimLink=true --self-contained dotnet publish -r linux-x64 -c release /p:RestoreLockedMode=true /p:TrimLink=true --self-contained
cd src/bin/x64/Release/net6.0/linux-x64/publish cd src/bin/x64/Release/net7.0/linux-x64/publish
cp AvaloniaCoreRTDemo AvaloniaCoreRTDemo.bin cp AvaloniaCoreRTDemo AvaloniaCoreRTDemo.bin
strip AvaloniaCoreRTDemo.bin strip AvaloniaCoreRTDemo.bin