RFBCodeWorks.Mvvm.WebView2Integration
1.0.2
See the version list below for details.
dotnet add package RFBCodeWorks.Mvvm.WebView2Integration --version 1.0.2
NuGet\Install-Package RFBCodeWorks.Mvvm.WebView2Integration -Version 1.0.2
<PackageReference Include="RFBCodeWorks.Mvvm.WebView2Integration" Version="1.0.2" />
paket add RFBCodeWorks.Mvvm.WebView2Integration --version 1.0.2
#r "nuget: RFBCodeWorks.Mvvm.WebView2Integration, 1.0.2"
// Install RFBCodeWorks.Mvvm.WebView2Integration as a Cake Addin #addin nuget:?package=RFBCodeWorks.Mvvm.WebView2Integration&version=1.0.2 // Install RFBCodeWorks.Mvvm.WebView2Integration as a Cake Tool #tool nuget:?package=RFBCodeWorks.Mvvm.WebView2Integration&version=1.0.2
RFBCodeWorks.Mvvm.WebView2Integration
This is a helper namespace to allow MVVM binding to navigation events generated by the Microsoft WebView2 object
IWebView2NavigationHandler
- This interface is used to react to the NavigationStarted and NavigationCompleted events generated by WebView2.
IWebView2NavigationHandlerExpanded
- This interface expands the amount of event handlers that are implemented,
WebView2BindingHelper
- This is a FrameWorkElement that must be added to the XAML to facilitate the event binding.
- Bind the WebView and an IWebView2NavigationHandler to allow for MVVM handling of the WebView2 navigation events.
- This object has a strong reference to the WebView2 object, as it must listen to the events.
- The IWebView2NavigationHandler methods are invoked when a WebView2 event occurs, and are not directly tied to the WebView2 control, facilitating a weak reference methodology via the binding.
NavigationHandler
Provides the NavigationHandler class that implements the required interface to allow for easy integration into existing viewmodels.
- Add the NavigationHandler to your viewmodel, then assign it the event delegate you wish to invoke when the event occurs.
- Finally, bind it all in xaml using the WebView2BindingHelper xaml object
Using this class, you can structure your ViewModel in such a way that all events are available to react against, but you only need to implement the desired few.
Example Usage:
xmlns:MyWebView="clr-namespace:RFBCodeWorks.Mvvm.WebView2Integration;assembly=RFBCodeWorks.Mvvm.WebView2Integration"
<grid>
<WebView:WebView2 x:Name="WV" Source="{Binding InitialSource}" />
<MyWebView:WebView2BindingHelper WebView="{Binding ElementName=WV}" NavigationHandler="{Binding NavigationHandler}"/>
</grid>
MyNavHandler = new NavigationHandler() { NavigationStartingHandler = PreventPageNavigation, NavigationCompletedHandler = OnNavigationComplete, };
private void PreventPageNavigation(object sender, CoreWebView2NavigationStartingEventArgs e) { e.Cancel = true; }
private void OnNavigationComplete(object sender, EventArgs e) { // do something }
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net5.0-windows7.0 is compatible. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net6.0-windows7.0 is compatible. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net7.0-windows7.0 is compatible. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net8.0-windows7.0 is compatible. |
.NET Core | netcoreapp3.1 is compatible. |
.NET Framework | net472 is compatible. net48 is compatible. net481 was computed. |
-
.NETCoreApp 3.1
- CommunityToolkit.Mvvm (>= 8.3.0)
- Microsoft.Web.WebView2 (>= 1.0.2739.15)
-
.NETFramework 4.7.2
- CommunityToolkit.Mvvm (>= 8.3.0)
- Microsoft.Web.WebView2 (>= 1.0.2739.15)
-
.NETFramework 4.8
- CommunityToolkit.Mvvm (>= 8.3.0)
- Microsoft.Web.WebView2 (>= 1.0.2739.15)
-
net5.0-windows7.0
- CommunityToolkit.Mvvm (>= 8.3.0)
- Microsoft.Web.WebView2 (>= 1.0.2739.15)
-
net6.0-windows7.0
- CommunityToolkit.Mvvm (>= 8.3.0)
- Microsoft.Web.WebView2 (>= 1.0.2739.15)
-
net7.0-windows7.0
- CommunityToolkit.Mvvm (>= 8.3.0)
- Microsoft.Web.WebView2 (>= 1.0.2739.15)
-
net8.0-windows7.0
- CommunityToolkit.Mvvm (>= 8.3.0)
- Microsoft.Web.WebView2 (>= 1.0.2739.15)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
- Added UriConverter to convert from URI to string and back
- Updated NavigationHandler to include some common-use RelayCommands and methods / properties for interacting with the currently loaded page.