<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>WPF on 唐璞玉</title>
    <link>https://sugarbearr.github.io/tags/wpf/</link>
    <description>Recent content in WPF on 唐璞玉</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>zh-cn</language>
    <lastBuildDate>Thu, 18 Jan 2024 22:18:15 +0800</lastBuildDate>
    <atom:link href="https://sugarbearr.github.io/tags/wpf/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>webview2在wpf中的应用</title>
      <link>https://sugarbearr.github.io/posts/webview2%E5%9C%A8wpf%E4%B8%AD%E7%9A%84%E5%BA%94%E7%94%A8/</link>
      <pubDate>Thu, 18 Jan 2024 22:18:15 +0800</pubDate>
      <guid>https://sugarbearr.github.io/posts/webview2%E5%9C%A8wpf%E4%B8%AD%E7%9A%84%E5%BA%94%E7%94%A8/</guid>
      <description>开发环境 运行环境：.Net 6
开发环境：Visual Studio 2022 17.1.3
框架语言：WPF
安装WebView2 通过Package Manager控制台安装 Install-Package Microsoft.Web.WebView2 通过Nuget包管理器安装 !https://s1.ax1x.com/2022/04/09/LinhIe.png
在窗体中添加名字空间： xmlns:wv2=&amp;#34;clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf&amp;#34; 引用WebView2控件： &amp;lt;wv2:WebView2 x:Name=&amp;#34;webview&amp;#34; Grid.Row=&amp;#34;1&amp;#34; Source=&amp;#34;&amp;lt;https://www.bilibili.com&amp;gt;&amp;#34; /&amp;gt; 使用WebView2 关于CoreWebView2 💡 Note：默认情况下，如果控件中没有设置Source属性，CoreWebView2是没有初始化的，此时需要我们手动初始化CoreWebView2，CoreWebView2初始化有以下两种方式：
第一种：调用EnsureCoreWebView2Async()方法 if (webView.CoreWebView2 == null) { await webView.EnsureCoreWebView2Async(); } 第二种：为Source属性赋值 webView.Source = new Url(&amp;#34;&amp;lt;https://www.bilibili.com&amp;gt;&amp;#34;); 常用设置 从初始化方式说起： var env = await CoreWebView2Environment.CreateAsync(); await webView.EnsureCoreWebView2Async(env); 这和我们最开始讲的初始化相比，多传了一个env变量参数来初始化。这个变量的工厂函数定义如下：
public static async Task&amp;lt;CoreWebView2Environment&amp;gt; CreateAsync( string browserExecutableFolder = null, string userDataFolder = null, CoreWebView2EnvironmentOptions options = null) 从以上代码可以看出，这个工厂函数它可以传入三个参数：
browserExecutableFolder userDataFolder options 第一个参数是选择Edge Runtime，默认为长绿版本，但我们也可以选择固定版本，当我们要使用固定版本时，需要做以下操作：</description>
    </item>
  </channel>
</rss>
