detect/detect.gui/Views/WebBrowserWindow.axaml.cs

46 lines
1.3 KiB
C#
Raw Normal View History

2024-11-21 16:28:36 +08:00
using Avalonia.Controls;
2024-11-13 17:09:15 +08:00
using Avalonia.Markup.Xaml;
using Avalonia.Platform;
2024-11-15 14:49:29 +08:00
using detect.gui.Services;
2024-11-13 17:09:15 +08:00
using detect.gui.ViewModels;
2024-11-15 14:49:29 +08:00
using Serilog;
using Splat;
2024-11-15 15:58:09 +08:00
using WebViewControl;
2024-11-13 17:09:15 +08:00
namespace detect.gui.Views;
public partial class WebBrowserWindow : Window
{
2024-11-14 17:11:43 +08:00
public UserControl? ParentContent { get; set; }
2024-11-13 17:09:15 +08:00
public WebBrowserWindow()
{
InitializeComponent();
DataContext = new WebViewModel();
ExtendClientAreaToDecorationsHint = true;
ExtendClientAreaChromeHints = ExtendClientAreaChromeHints.NoChrome;
ExtendClientAreaTitleBarHeightHint = -1;
SystemDecorations = SystemDecorations.None;
2024-11-21 17:47:13 +08:00
ShowInTaskbar = false;
Topmost = true;
2024-11-13 17:09:15 +08:00
CanResize = false;
2024-11-15 14:49:29 +08:00
2024-11-15 15:58:09 +08:00
var webview = this.Get<WebView>("WebView");
2024-11-15 15:01:03 +08:00
var service = Locator.Current.GetService<DeviceClientService>();
2024-11-15 15:58:09 +08:00
webview.RegisterJavascriptObject("DeviceClientService", service);
2024-11-21 16:28:36 +08:00
webview.RegisterJavascriptObject("WebViewService", new WebViewService(this));
2024-11-15 15:58:09 +08:00
Log.Information("WebView Initialized.");
2024-11-13 17:09:15 +08:00
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
public void SetAddress(int index)
{
(DataContext as WebViewModel)!.SetAddress(index);
}
}