diff --git a/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc.Browser/AA05_CommandParCalc.Browser.csproj b/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc.Browser/AA05_CommandParCalc.Browser.csproj new file mode 100644 index 000000000..cdab5ea0b --- /dev/null +++ b/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc.Browser/AA05_CommandParCalc.Browser.csproj @@ -0,0 +1,24 @@ + + + + net10.0-browser + Exe + true + enable + + + + + + + + + + + + + + + + + diff --git a/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc.Browser/Program.cs b/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc.Browser/Program.cs new file mode 100644 index 000000000..eb2c75a10 --- /dev/null +++ b/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc.Browser/Program.cs @@ -0,0 +1,22 @@ +using AA05_CommandParCalc; +using Avalonia; +using Avalonia.Browser; +using System.Runtime.Versioning; +using System.Threading.Tasks; + +[assembly: SupportedOSPlatform("browser")] + +internal sealed partial class Program +{ + private static async Task Main(string[] args) + { + await BrowserAppBuilder.StartBrowserAppAsync( + BuildAvaloniaApp() + .WithInterFont(), + "out", + new BrowserPlatformOptions()); + } + + public static AppBuilder BuildAvaloniaApp() + => AppBuilder.Configure(); +} \ No newline at end of file diff --git a/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc.Browser/Properties/AssemblyInfo.cs b/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc.Browser/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..fb787959a --- /dev/null +++ b/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc.Browser/Properties/AssemblyInfo.cs @@ -0,0 +1 @@ +[assembly:System.Runtime.Versioning.SupportedOSPlatform("browser")] diff --git a/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc.Browser/Properties/launchSettings.json b/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc.Browser/Properties/launchSettings.json new file mode 100644 index 000000000..34f7c14f4 --- /dev/null +++ b/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc.Browser/Properties/launchSettings.json @@ -0,0 +1,38 @@ +{ + "profiles": { + "AA05_CommandParCalc.Browser": { + "commandName": "Project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "https://localhost:7170;http://localhost:5236", + "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}" + }, + "WSL": { + "commandName": "WSL2", + "launchBrowser": true, + "launchUrl": "https://localhost:7170", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development", + "ASPNETCORE_URLS": "https://localhost:7170;http://localhost:5236" + }, + "distributionName": "" + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + }, + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:57862/", + "sslPort": 44327 + } + } +} \ No newline at end of file diff --git a/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc.Browser/runtimeconfig.template.json b/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc.Browser/runtimeconfig.template.json new file mode 100644 index 000000000..e2af20d1d --- /dev/null +++ b/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc.Browser/runtimeconfig.template.json @@ -0,0 +1,10 @@ +{ + "wasmHostProperties": { + "perHostConfig": [ + { + "name": "browser", + "host": "browser" + } + ] + } +} diff --git a/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc.Browser/wwwroot/app.css b/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc.Browser/wwwroot/app.css new file mode 100644 index 000000000..1413eee39 --- /dev/null +++ b/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc.Browser/wwwroot/app.css @@ -0,0 +1,57 @@ +/* HTML styles for the splash screen */ +.avalonia-splash { + position: absolute; + height: 100%; + width: 100%; + background: white; + font-family: 'Outfit', sans-serif; + justify-content: center; + align-items: center; + display: flex; + pointer-events: none; +} + +@media (prefers-color-scheme: light) { + .avalonia-splash { + background: white; + } + + .avalonia-splash h2 { + color: #1b2a4e; + } + + .avalonia-splash a { + color: #0D6EFD; + } +} + +@media (prefers-color-scheme: dark) { + .avalonia-splash { + background: #1b2a4e; + } + + .avalonia-splash h2 { + color: white; + } + + .avalonia-splash a { + color: white; + } +} + +.avalonia-splash h2 { + font-weight: 400; + font-size: 1.5rem; +} + +.avalonia-splash a { + text-decoration: none; + font-size: 2.5rem; + display: block; +} + +.avalonia-splash.splash-close { + transition: opacity 200ms, display 200ms; + display: none; + opacity: 0; +} diff --git a/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc.Browser/wwwroot/index.html b/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc.Browser/wwwroot/index.html new file mode 100644 index 000000000..77d73a2c1 --- /dev/null +++ b/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc.Browser/wwwroot/index.html @@ -0,0 +1,17 @@ + + + + AA05_CommandParCalc.Browser + + + + + +
+
+

AA05 CommandParCalc is loading...

+
+
+ + + diff --git a/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc.Browser/wwwroot/main.js b/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc.Browser/wwwroot/main.js new file mode 100644 index 000000000..bf1555e43 --- /dev/null +++ b/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc.Browser/wwwroot/main.js @@ -0,0 +1,13 @@ +import { dotnet } from './_framework/dotnet.js' + +const is_browser = typeof window != "undefined"; +if (!is_browser) throw new Error(`Expected to be running in a browser`); + +const dotnetRuntime = await dotnet + .withDiagnosticTracing(false) + .withApplicationArgumentsFromQuery() + .create(); + +const config = dotnetRuntime.getConfig(); + +await dotnetRuntime.runMain(config.mainAssemblyName, [globalThis.location.href]); diff --git a/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc.Desktop/AA05_CommandParCalc.Desktop.csproj b/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc.Desktop/AA05_CommandParCalc.Desktop.csproj new file mode 100644 index 000000000..e18da5b4c --- /dev/null +++ b/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc.Desktop/AA05_CommandParCalc.Desktop.csproj @@ -0,0 +1,32 @@ + + + + WinExe + net8.0 + true + app.manifest + + + + + $(TargetFrameworks);net9.0 + + + $(TargetFrameworks);net10.0 + + + $(TargetFrameworks);net11.0 + + + + + + None + All + + + + + + + diff --git a/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc.Desktop/Program.cs b/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc.Desktop/Program.cs new file mode 100644 index 000000000..e9f1a0c53 --- /dev/null +++ b/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc.Desktop/Program.cs @@ -0,0 +1,20 @@ +using AA05_CommandParCalc; +using Avalonia; +using System; + +namespace AA05_CommandParCalc.Desktop; + +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() + => AppBuilderFactory.BuildAvaloniaApp() + .UsePlatformDetect(); +} diff --git a/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc.Desktop/app.manifest b/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc.Desktop/app.manifest new file mode 100644 index 000000000..a606865f7 --- /dev/null +++ b/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc.Desktop/app.manifest @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc/AA05_CommandParCalc.csproj b/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc/AA05_CommandParCalc.csproj index d8f1914f1..1fd76f755 100644 --- a/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc/AA05_CommandParCalc.csproj +++ b/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc/AA05_CommandParCalc.csproj @@ -1,10 +1,8 @@  - WinExe net8.0 - true - app.manifest + enable true @@ -21,15 +19,9 @@ - - - - None - All - diff --git a/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc/App.axaml.cs b/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc/App.axaml.cs index 9933e996c..c3f963c1b 100644 --- a/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc/App.axaml.cs +++ b/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc/App.axaml.cs @@ -2,7 +2,6 @@ using Avalonia; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Markup.Xaml; -using Avalonia.Platform; using AA05_CommandParCalc.Models; using AA05_CommandParCalc.Models.Interfaces; using AA05_CommandParCalc.ViewModels; @@ -14,6 +13,8 @@ namespace AA05_CommandParCalc; public partial class App : Application { + public IServiceProvider? Services { get; private set; } + public override void Initialize() { AvaloniaXamlLoader.Load(this); @@ -21,31 +22,35 @@ public override void Initialize() public override void OnFrameworkInitializationCompleted() { + Services = CreateServices(); + if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { - InitDesktopApp(desktop); + desktop.MainWindow = new MainWindow + { + DataContext = Services.GetRequiredService() + }; + } + else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewPlatform) + { + singleViewPlatform.MainView = new CommandParCalcView + { + DataContext = Services.GetRequiredService() + }; } base.OnFrameworkInitializationCompleted(); } - protected void InitDesktopApp(IClassicDesktopStyleApplicationLifetime desktop) + private static IServiceProvider CreateServices() { var services = new ServiceCollection(); services.AddTransient() .AddTransient() .AddTransient() - .AddSingleton((s)=>null!) .AddSingleton(); - Services = services.BuildServiceProvider(); - - desktop.MainWindow = new MainWindow - { - DataContext = Services.GetRequiredService() - }; + return services.BuildServiceProvider(); } - - public IServiceProvider? Services { get; private set; } } diff --git a/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc/Models/CommandParCalcModel.cs b/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc/Models/CommandParCalcModel.cs index 4f75e1068..3fecaec4f 100644 --- a/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc/Models/CommandParCalcModel.cs +++ b/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc/Models/CommandParCalcModel.cs @@ -11,16 +11,9 @@ // // // *********************************************************************** -using Avalonia.Platform; using AA05_CommandParCalc.Models.Interfaces; using CommunityToolkit.Mvvm.ComponentModel; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using System.Timers; /// /// The Models namespace. @@ -32,21 +25,15 @@ namespace AA05_CommandParCalc.Models; /// public partial class CommandParCalcModel : ObservableObject, ICommandParCalcModel { - /// - /// The platform handle - /// - private IPlatformHandle _platformHandle; - private ISysTime _sysTime; - private ICyclTimer _timer; + private readonly ISysTime _sysTime; + private readonly ICyclTimer _timer; public DateTime Now => _sysTime.Now; /// /// Initializes a new instance of the class. /// - /// The platform handle. - public CommandParCalcModel(IPlatformHandle platformHandle, ISysTime sysTime, ICyclTimer timer) + public CommandParCalcModel(ISysTime sysTime, ICyclTimer timer) { - _platformHandle = platformHandle; _sysTime = sysTime; _timer = timer; _timer.Interval = 1000; diff --git a/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc/Program.cs b/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc/Program.cs index c69cb92e5..2151b0b52 100644 --- a/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc/Program.cs +++ b/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc/Program.cs @@ -20,40 +20,25 @@ namespace AA05_CommandParCalc; /// -/// Class Program. This class cannot be inherited. +/// Provides the shared Avalonia application builder. /// -public sealed class Program +public static class AppBuilderFactory { - // 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. /// - /// Defines the entry point of the application. - /// - /// The arguments. - [STAThread] - public static void Main(string[] args) - => BuildAvaloniaApp() - .StartWithClassicDesktopLifetime(args); - - // Avalonia configuration, don't remove; also used by visual designer. - /// - /// Builds the avalonia application. + /// Builds the shared Avalonia application. /// /// AppBuilder. - public static AppBuilder BuildAvaloniaApp() //{ get; set; } = () + public static AppBuilder BuildAvaloniaApp() => GetAppBuilder(); /// - /// Builds the avalonia application. + /// Gets the application builder factory. /// - /// AppBuilder. + /// A delegate returning the configured . public static Func GetAppBuilder = CreateAppBuilder; private static AppBuilder CreateAppBuilder() => AppBuilder.Configure() - .UsePlatformDetect() .WithInterFont() .LogToTrace(); - } diff --git a/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalcTests/AppTests.cs b/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalcTests/AppTests.cs index 7e2a2666c..ba24dd5aa 100644 --- a/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalcTests/AppTests.cs +++ b/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalcTests/AppTests.cs @@ -1,16 +1,9 @@ using NSubstitute; using Avalonia.Controls.ApplicationLifetimes; -using Avalonia.Platform; namespace AA05_CommandParCalc.Tests; -class TestApp : App -{ - public void CallInitDesktopApp() - { - InitDesktopApp(Substitute.For()); - } -} +class TestApp : App; [TestClass()] public class AppTests @@ -47,31 +40,35 @@ public void InitializeTest() [TestMethod()] public void InitDesktopTest() { - // Act - Assert.ThrowsExactly(()=> testApp.CallInitDesktopApp()); + testApp.ApplicationLifetime = Substitute.For(); + + Assert.ThrowsExactly(() => testApp.OnFrameworkInitializationCompleted()); - // Assert Assert.IsNotNull(testApp.Services); - Assert.IsNull(testApp.Services.GetService(typeof(IPlatformHandle))); } [TestMethod()] public void OnFrameworkInitializationCompletedTest() { testApp.ApplicationLifetime = Substitute.For(); + // Act - Assert.ThrowsExactly(()=> testApp.OnFrameworkInitializationCompleted()); + Assert.ThrowsExactly(() => testApp.OnFrameworkInitializationCompleted()); + + // Assert + Assert.IsNotNull(testApp.Services); } [TestMethod()] public void OnFrameworkInitializationCompletedTest2() { testApp.ApplicationLifetime = Substitute.For(); + // Act testApp.OnFrameworkInitializationCompleted(); // Assert - Assert.IsNull(testApp.Services); + Assert.IsNotNull(testApp.Services); } } diff --git a/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalcTests/Models/CommandParCalcModelTests.cs b/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalcTests/Models/CommandParCalcModelTests.cs index 59d1581d3..787cd4ebc 100644 --- a/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalcTests/Models/CommandParCalcModelTests.cs +++ b/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalcTests/Models/CommandParCalcModelTests.cs @@ -1,6 +1,5 @@ using AA05_CommandParCalc.Models.Interfaces; using NSubstitute; -using Avalonia.Platform; using System.ComponentModel; namespace AA05_CommandParCalc.Models.Tests; @@ -18,8 +17,7 @@ public void TestInitialize() var tmr = Substitute.For(); var st = Substitute.For(); st.Now.Returns(new DateTime(2025,1,2)); - var pfh = Substitute.For(); - testModel = new CommandParCalcModel(pfh,st,tmr); + testModel = new CommandParCalcModel(st,tmr); } [TestMethod()] diff --git a/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalcTests/ProgramTests.cs b/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalcTests/ProgramTests.cs index 3015db81b..7ae9e938d 100644 --- a/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalcTests/ProgramTests.cs +++ b/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalcTests/ProgramTests.cs @@ -1,4 +1,5 @@ using Avalonia; +using AA05_CommandParCalc; namespace AA05_CommandParCalc.Tests { @@ -7,24 +8,28 @@ public class ProgramTests { [TestMethod()] - public void MainTest() + public void BuildAvaloniaAppUsesConfigurableFactoryTest() { - var _baa = Program.GetAppBuilder; + var appBuilderFactory = AppBuilderFactory.GetAppBuilder; try { - Program.GetAppBuilder = () => AppBuilder.Configure(); - Assert.ThrowsExactly(()=> Program.Main(new string[] { })); + AppBuilderFactory.GetAppBuilder = () => AppBuilder.Configure(); + + var result = AppBuilderFactory.BuildAvaloniaApp(); + + Assert.IsNotNull(result); + Assert.IsInstanceOfType(result, typeof(AppBuilder)); } finally { - Program.GetAppBuilder = _baa; + AppBuilderFactory.GetAppBuilder = appBuilderFactory; } } [TestMethod()] public void BuildAvaloniaAppTest() { - var result = Program.BuildAvaloniaApp(); + var result = AppBuilderFactory.BuildAvaloniaApp(); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(AppBuilder)); } diff --git a/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalcTests/ViewLocatorTests.cs b/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalcTests/ViewLocatorTests.cs index d0aa33aaa..bc7376832 100644 --- a/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalcTests/ViewLocatorTests.cs +++ b/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalcTests/ViewLocatorTests.cs @@ -76,7 +76,6 @@ public void BuildTest(string sAct,string sExp) obj = Activator.CreateInstance(tAct); else obj = Activator.CreateInstance(tAct, [ - null, Substitute.For(), Substitute.For() ]); diff --git a/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes.Browser/AA09_DialogBoxes.Browser.csproj b/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes.Browser/AA09_DialogBoxes.Browser.csproj new file mode 100644 index 000000000..c8d8f3394 --- /dev/null +++ b/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes.Browser/AA09_DialogBoxes.Browser.csproj @@ -0,0 +1,24 @@ + + + + net10.0-browser + Exe + true + enable + + + + + + + + + + + + + + + + + diff --git a/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes.Browser/Program.cs b/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes.Browser/Program.cs new file mode 100644 index 000000000..88b283575 --- /dev/null +++ b/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes.Browser/Program.cs @@ -0,0 +1,22 @@ +using AA09_DialogBoxes; +using Avalonia; +using Avalonia.Browser; +using System.Runtime.Versioning; +using System.Threading.Tasks; + +[assembly: SupportedOSPlatform("browser")] + +internal sealed partial class Program +{ + private static async Task Main(string[] args) + { + await BrowserAppBuilder.StartBrowserAppAsync( + BuildAvaloniaApp() + .WithInterFont(), + "out", + new BrowserPlatformOptions()); + } + + public static AppBuilder BuildAvaloniaApp() + => AppBuilder.Configure(); +} \ No newline at end of file diff --git a/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes.Browser/Properties/AssemblyInfo.cs b/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes.Browser/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..fb787959a --- /dev/null +++ b/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes.Browser/Properties/AssemblyInfo.cs @@ -0,0 +1 @@ +[assembly:System.Runtime.Versioning.SupportedOSPlatform("browser")] diff --git a/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes.Browser/Properties/launchSettings.json b/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes.Browser/Properties/launchSettings.json new file mode 100644 index 000000000..279f3844a --- /dev/null +++ b/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes.Browser/Properties/launchSettings.json @@ -0,0 +1,38 @@ +{ + "profiles": { + "WSL": { + "commandName": "WSL2", + "launchBrowser": true, + "launchUrl": "https://localhost:7170", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development", + "ASPNETCORE_URLS": "https://localhost:7170;http://localhost:5236" + }, + "distributionName": "" + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "AA09_DialogBoxes.Browser": { + "commandName": "Project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "https://localhost:7170;http://localhost:5236", + "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}" + } + }, + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:57862/", + "sslPort": 44327 + } + } +} \ No newline at end of file diff --git a/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes.Browser/runtimeconfig.template.json b/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes.Browser/runtimeconfig.template.json new file mode 100644 index 000000000..e2af20d1d --- /dev/null +++ b/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes.Browser/runtimeconfig.template.json @@ -0,0 +1,10 @@ +{ + "wasmHostProperties": { + "perHostConfig": [ + { + "name": "browser", + "host": "browser" + } + ] + } +} diff --git a/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes.Browser/wwwroot/app.css b/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes.Browser/wwwroot/app.css new file mode 100644 index 000000000..1413eee39 --- /dev/null +++ b/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes.Browser/wwwroot/app.css @@ -0,0 +1,57 @@ +/* HTML styles for the splash screen */ +.avalonia-splash { + position: absolute; + height: 100%; + width: 100%; + background: white; + font-family: 'Outfit', sans-serif; + justify-content: center; + align-items: center; + display: flex; + pointer-events: none; +} + +@media (prefers-color-scheme: light) { + .avalonia-splash { + background: white; + } + + .avalonia-splash h2 { + color: #1b2a4e; + } + + .avalonia-splash a { + color: #0D6EFD; + } +} + +@media (prefers-color-scheme: dark) { + .avalonia-splash { + background: #1b2a4e; + } + + .avalonia-splash h2 { + color: white; + } + + .avalonia-splash a { + color: white; + } +} + +.avalonia-splash h2 { + font-weight: 400; + font-size: 1.5rem; +} + +.avalonia-splash a { + text-decoration: none; + font-size: 2.5rem; + display: block; +} + +.avalonia-splash.splash-close { + transition: opacity 200ms, display 200ms; + display: none; + opacity: 0; +} diff --git a/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes.Browser/wwwroot/index.html b/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes.Browser/wwwroot/index.html new file mode 100644 index 000000000..fff9eed6a --- /dev/null +++ b/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes.Browser/wwwroot/index.html @@ -0,0 +1,17 @@ + + + + AA09_DialogBoxes.Browser + + + + + +
+
+

AA09 DialogBoxes is loading...

+
+
+ + + diff --git a/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes.Browser/wwwroot/main.js b/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes.Browser/wwwroot/main.js new file mode 100644 index 000000000..bf1555e43 --- /dev/null +++ b/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes.Browser/wwwroot/main.js @@ -0,0 +1,13 @@ +import { dotnet } from './_framework/dotnet.js' + +const is_browser = typeof window != "undefined"; +if (!is_browser) throw new Error(`Expected to be running in a browser`); + +const dotnetRuntime = await dotnet + .withDiagnosticTracing(false) + .withApplicationArgumentsFromQuery() + .create(); + +const config = dotnetRuntime.getConfig(); + +await dotnetRuntime.runMain(config.mainAssemblyName, [globalThis.location.href]); diff --git a/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes.Desktop/AA09_DialogBoxes.Desktop.csproj b/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes.Desktop/AA09_DialogBoxes.Desktop.csproj new file mode 100644 index 000000000..d1afb703c --- /dev/null +++ b/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes.Desktop/AA09_DialogBoxes.Desktop.csproj @@ -0,0 +1,32 @@ + + + + WinExe + net8.0 + true + app.manifest + + + + + $(TargetFrameworks);net9.0 + + + $(TargetFrameworks);net10.0 + + + $(TargetFrameworks);net11.0 + + + + + + None + All + + + + + + + diff --git a/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes.Desktop/Program.cs b/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes.Desktop/Program.cs new file mode 100644 index 000000000..886920af6 --- /dev/null +++ b/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes.Desktop/Program.cs @@ -0,0 +1,22 @@ +using AA09_DialogBoxes; +using Avalonia; +using System; + +namespace AA09_DialogBoxes.Desktop; + +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() + .WithInterFont() + .LogToTrace(); +} diff --git a/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes.Desktop/app.manifest b/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes.Desktop/app.manifest new file mode 100644 index 000000000..a606865f7 --- /dev/null +++ b/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes.Desktop/app.manifest @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes/AA09_DialogBoxes.csproj b/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes/AA09_DialogBoxes.csproj index ad21ab48a..e117a1b32 100644 --- a/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes/AA09_DialogBoxes.csproj +++ b/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes/AA09_DialogBoxes.csproj @@ -1,7 +1,6 @@  - WinExe net8.0 true @@ -13,12 +12,19 @@ $(TargetFrameworks);net10.0 - + + $(TargetFrameworks);net11.0 + + + $(TargetFrameworks);net11.0 + + enable disable + @@ -34,6 +40,7 @@ All + diff --git a/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes/App.axaml.cs b/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes/App.axaml.cs index 056048e1d..3a1ea5dd4 100644 --- a/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes/App.axaml.cs +++ b/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes/App.axaml.cs @@ -11,14 +11,23 @@ // // // *********************************************************************** +using AA09_DialogBoxes.ViewModels; +using AA09_DialogBoxes.Views; using Avalonia; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Markup.Xaml; +using BaseLib.Models; +using BaseLib.Models.Interfaces; +using Microsoft.Extensions.DependencyInjection; +using System; namespace AA09_DialogBoxes; public partial class App : Application { + + public IServiceProvider? Services { get; private set; } + public override void Initialize() { AvaloniaXamlLoader.Load(this); @@ -26,13 +35,35 @@ public override void Initialize() public override void OnFrameworkInitializationCompleted() { + Services = CreateServices(); + if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { - desktop.MainWindow = new Views.MainWindow + desktop.MainWindow = new MainWindow + { + DataContext = Services.GetRequiredService() + }; + } + else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewPlatform) + { + singleViewPlatform.MainView = new BrowserMainView { + DataContext = Services.GetRequiredService() }; } base.OnFrameworkInitializationCompleted(); } + + private static IServiceProvider CreateServices() + { + var services = new ServiceCollection(); + + services + .AddTransient() + .AddTransient() + .AddTransient(); + + return services.BuildServiceProvider(); + } } diff --git a/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes/Views/BrowserEditDialogControl.axaml b/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes/Views/BrowserEditDialogControl.axaml new file mode 100644 index 000000000..aa884e1a4 --- /dev/null +++ b/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes/Views/BrowserEditDialogControl.axaml @@ -0,0 +1,59 @@ + + + + + + + + + + + +