WebView2在WPF/Windows表单内部的WebView2 Control for VSTO Project
我已经创建了一个使用WPF用户控件的 C#Outlook VSTO项目,该项目嵌入了Windows表单。
这个想法是使用添加到WPF用户控件中的WebView2控件导航到特定网站。
问题是该控件没有渲染任何网站。另一方面,当我在其他项目中使用windows表单或wpf在其他项目中使用WebView2控件时。
我正在使用“ Microsoft.web.webview2”
这是我的Windows表单代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace FraudDetector.Controls
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
this.eHost.Child = new FDView();
}
}
}
这是我的WPF XAML:
<UserControl
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:FraudDetector.Controls"
xmlns:Wpf="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid Background="Red">
<Wpf:WebView2 Source="https://www.google.com/"/>
</Grid>
</UserControl>
有人有一些想法吗?
I have created a C# Outlook VSTO project with a wpf User control which is embedded in a Windows Form.
The idea is to navigate to an specific website using the WebView2 control that was added to the wpf User control.
The issue is that the control isn't rendering any website. On the other hand when I use a WebView2 control in a different project just with the Windows Form or WPF it works.
The package I'm using "Microsoft.Web.WebView2"
This is my Windows Form code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace FraudDetector.Controls
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
this.eHost.Child = new FDView();
}
}
}
This is my wpf xaml:
<UserControl
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:FraudDetector.Controls"
xmlns:Wpf="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid Background="Red">
<Wpf:WebView2 Source="https://www.google.com/"/>
</Grid>
</UserControl>
Do some one have some idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我发现在WebView2中设置UserDataFolder(也称为“ CACHE”)的解决方案:
tempwebcachedir 是设置用户datafolder的目录。
corewebview2environment.createasync(userDataFolder:tempwebcachedir)用于创建一个新的corewebview2enview2environment,并将用户datafolder设置为指定目录。
Here's the solution I found to set the userDataFolder (also called "cache") in WebView2:
The tempWebCacheDir is the directory where the userDataFolder will be set.
CoreWebView2Environment.CreateAsync(userDataFolder: tempWebCacheDir) is used to create a new CoreWebView2Environment with the userDataFolder set to the specified directory.