我尝试按照文档中的解释来捕捉事件ContentLoading。https:/docs.microsoft.comen-uswindowscommunitytoolkitcontrolswpf-winformswebview。
但我有一个错误的行:
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>
谢谢你
好吧,我发现了我的错误:我不能直接在窗口中添加一个来自工具包的WebView,而是在UserControl中添加,之后,如果我的类继承了UserControl,我就可以处理该事件。