csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.1 KiB
47 lines
1.1 KiB
using System;
|
|
using Avalonia.Controls;
|
|
using Avalonia.Controls.ApplicationLifetimes;
|
|
using System.Runtime.Versioning;
|
|
|
|
namespace Avalonia.Browser;
|
|
|
|
public class BrowserSingleViewLifetime : ISingleViewApplicationLifetime
|
|
{
|
|
public AvaloniaView? View;
|
|
|
|
public Control? MainView
|
|
{
|
|
get => View!.Content;
|
|
set => View!.Content = value;
|
|
}
|
|
}
|
|
|
|
public class BrowserPlatformOptions
|
|
{
|
|
public Func<string, string> FrameworkAssetPathResolver { get; set; } = new(fileName => $"./{fileName}");
|
|
}
|
|
|
|
public static class WebAppBuilder
|
|
{
|
|
public static AppBuilder SetupBrowserApp(
|
|
this AppBuilder builder, string mainDivId)
|
|
{
|
|
var lifetime = new BrowserSingleViewLifetime();
|
|
|
|
return builder
|
|
.UseBrowser()
|
|
.AfterSetup(b =>
|
|
{
|
|
lifetime.View = new AvaloniaView(mainDivId);
|
|
})
|
|
.SetupWithLifetime(lifetime);
|
|
}
|
|
|
|
public static AppBuilder UseBrowser(
|
|
this AppBuilder builder)
|
|
{
|
|
return builder
|
|
.UseWindowingSubsystem(BrowserWindowingPlatform.Register)
|
|
.UseSkia();
|
|
}
|
|
}
|
|
|