贡献者对" Toolkit.win32.ui.controls"进行了一些更新。在他们自己的分支。我在项目中下载,编译和引用了生成的dll。我在对象浏览器中看到API更改(参见附图);但是,编译器似乎没有看到这些更改,因为每当我尝试使用其他API时都会出现错误。
分支:https://github.com/rjmurillo/UWPCommunityToolkit/tree/WebView/NavigateWithHttpMessage
他所做的改变: https://github.com/Microsoft/WindowsCommunityToolkit/pull/2195
发生错误的地方:
Uri url = webView.BuildLocalStreamUri("MyTag", "/Minesweeper/default.html");
错误:
Severity Code Description Project File Line Suppression State
Error CS1061 'WebView' does not contain a definition for 'BuildLocalStreamUri' and no extension method 'BuildLocalStreamUri' accepting a first argument of type 'WebView' could be found (are you missing a using directive or an assembly reference?) Test.WPF C:\Users\Adam\Desktop\Test.WPF\MainWindow.xaml.cs 29 Active
它几乎就像它仍在使用原始的,未经修改的引用版本,因为它确实识别了#34; WebView"。
XAML:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:SparkStore.WPF"
xmlns:winforms="clr-namespace:Microsoft.Toolkit.Win32.UI.Controls.WinForms;assembly=Microsoft.Toolkit.Win32.UI.Controls"
xmlns:WPF="clr-namespace:Microsoft.Toolkit.Win32.UI.Controls.WPF;assembly=Microsoft.Toolkit.Win32.UI.Controls" x:Class="Test.WPF.MainWindow"
mc:Ignorable="d"
Title="Test" Height="450" Width="800">
<Grid>
<WPF:WebView x:Name="webView" Margin="0"/>
</Grid>
</Window>
项目文件:
[![<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{525B29B6-0498-46D2-A1E9-EDBBFA4FA34D}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>Test.WPF</RootNamespace>
<AssemblyName>Test.WPF</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFrameworkProfile />
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Toolkit.Win32.UI.Controls">
<HintPath>..\UWPCommunityToolkit\Microsoft.Toolkit.Win32\Microsoft.Toolkit.Win32.UI.Controls\bin\AnyCPU\Release\net462\Microsoft.Toolkit.Win32.UI.Controls.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Design" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.6.1">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.6.1 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Resource Include="Readme.txt" />
</ItemGroup>
<Import Project="..\Test\Test.projitems" Label="Shared" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>][1]][1]
答案 0 :(得分:2)
WebView Toolkit版本的WebView的目标之一是提供WinRT和.NET概念之间的分离,并提供从Win32和UWP应用程序之间提供桥梁的性质和限制的抽象,因此省略了一些API从最初的发布。通过公开BuildLocalStreamUri(String, String)
而不进行任何抽象,返回值为托管Web视图的Win32WebViewHost UWP应用程序(例如ms-local-stream://microsoft.win32webviewhost_cw5n1h2txyewy_54657374/foo.htm
)提供了相对URI,而不是Windows窗体或WPF应用程序本身,这可能会让人感到困惑
提到的分支确实提供了对BuildLocalStreamUri
的支持,但是,它旨在在NavigateToLocalStreamUri(Uri, IUriToStreamResolver)
或NavigateToLocal(String)
的上下文中使用以提供该抽象。使用这些方法之一将在内部调用BuildLocalStreamUri
来规范化URI,并调用IUriToStreamResolver
的实例将资产转换为System.IO.Stream
。