首页 > 解决方案 > 无法在 WPF 控件工具包 WebView 上捕获事件 ContentLoading

问题描述

我尝试捕捉事件 ContentLoading 作为文档解释这里:https ://docs.microsoft.com/en-us/windows/communitytoolkit/controls/wpf-winforms/webview

但我在这行有一个错误:

WebviewEdge.ContentLoading += WebviewEdge_ContentLoading;

Error CS0123 No overload for 'WebviewEdge_ContentLoading' corresponds to the delegate 'EventHandler <WebViewControlContentLoadingEventArgs>'

我尝试将代码更改为:

WebviewEdge.ContentLoading += EventHandler <WebViewControlContentLoadingEventArgs>(WebviewEdge_ContentLoading);

但它不起作用,有什么想法吗?

这是我的xaml:

<Window
        x:Class="ArchiReport.ARWebview"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
        xmlns:local="clr-namespace:ArchiReport"
        xmlns:Controls="clr-namespace:Microsoft.Toolkit.Wpf.UI.Controls;assembly=Microsoft.Toolkit.Wpf.UI.Controls.WebView"
        SizeToContent="WidthAndHeight"             
        WindowStartupLocation="CenterScreen" 
        Topmost="True" 
        Width="491.25" Height="671.25" 
        Title="Connect" 
        WindowStyle="ThreeDBorderWindow" Foreground="#FFF3ECEC" 
        AutomationProperties.Name="WebConnect" 
        ShowInTaskbar="False">
    <Controls:WebView x:Name="WebviewEdge" 
        HorizontalAlignment="Left" Height="640" 
        VerticalAlignment="Top" Width="483" 
        Source="myurl.html"
        ContentLoading="WebviewEdge_ContentLoading"/>
</Window>

谢谢

标签: c#wpfwebvieweventhandler

解决方案


好的,我发现了我的错误:我不能直接在窗口中从工具包中添加 WebView,但是在 UserControl 中,之后,如果我的类继承自 UserControl,我可以处理该事件。


推荐阅读