c# - 无法在 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>
谢谢
解决方案
好的,我发现了我的错误:我不能直接在窗口中从工具包中添加 WebView,但是在 UserControl 中,之后,如果我的类继承自 UserControl,我可以处理该事件。
推荐阅读
- node.js - 如何正确找到 .txt 文件并使用 NodeJS 读取其内容
- python - SQL Alchemy - 混合属性 - 拆分列
- reactjs - 如何创建指向反应组件的路由
- php - PHP - 保护用户完整的 HTML 文件免受 XSS 攻击
- django - Django 自定义迁移 RunPython 无法访问另一个数据库中的 ForeignKey 字段
- reactjs - 将新文档添加到 Firestore 集合后打印重复列表
- magento2 - 如何在 Magento 2.3 的注册表单中添加客户组选择器?
- c# - ConfigureServices AddHttpClient 如何访问从 KeyVault 获取证书的自定义证书提供程序?
- javascript - 使用 Jasmine toEqual 未定义预期对象
- tatsu - Tatsu:规则排序