基于WebView2实现的Win11桌面框架,利用插件自定义
chunhualin1
2026-08-12 97df0fb5ed49e37d1c8e0e62057bb72ba5c9eb6a
src/Moli.Desktop/WebView/WebViewHost.cs
@@ -126,6 +126,39 @@
        return Task.CompletedTask;
    }
    public Task NotifyParentWindowPositionChangedAsync(CancellationToken cancellationToken = default)
    {
        if (!_initialized || Control.CoreWebView2 is null)
        {
            return Task.CompletedTask;
        }
        cancellationToken.ThrowIfCancellationRequested();
        try
        {
            var controllerProperty = Control.GetType().GetProperty("CoreWebView2Controller");
            if (controllerProperty?.GetValue(Control) is { } controller)
            {
                var method = controller.GetType().GetMethod("NotifyParentWindowPositionChanged");
                method?.Invoke(controller, null);
                return Task.CompletedTask;
            }
        }
        catch
        {
        }
        Control.Dispatcher.InvokeAsync(() =>
        {
            Control.InvalidateMeasure();
            Control.InvalidateArrange();
            Control.UpdateLayout();
        }, System.Windows.Threading.DispatcherPriority.Render);
        return Task.CompletedTask;
    }
    public async ValueTask DisposeAsync()
    {
        _audioSubscription?.Dispose();