Delphi7 Host. .Net WPF Plugin. WebView2

.Net Framework 4.8 WPF plugin containing WebView2. When deployed into a Delphi7 Host the webview doesn’t render.

When tested in VS2019 dev environment with a .Net host the webview renders correctly and displays html content.

The XAML containing the WebView is simple. The Red Stackpanel was added to test that the view was being displayed in Delphi Host. The PreviewMouse events added to catch a right click so we can log it. Right clicking when docked in Delphi doesn’t hit the events, again proving that the WebView hasn’t rendered on the page.

<UserControl x:Class="Savant.Pulse.Client.Plugin.PULHLP.Views.Main.MainView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:main="clr-namespace:Savant.Pulse.Client.Plugin.PULHLP.Views.Main"
             mc:Ignorable="d"
             xmlns:wv2="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
             DataContext="{dxmvvm:ViewModelSource Type=main:MainViewModel}"
             d:DataContext="{d:DesignInstance main:MainViewModel, IsDesignTimeCreatable=True}">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Savant.Pulse.Client.Wpf.Views;component/Styles/Styles.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>


    <Grid>
        <!--Top Section-->
        <Grid.RowDefinitions>
            <!--Tool Bar-->
            <RowDefinition Height="40"/>
            <!--Main Body-->
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <!--Tool Bar-->

        <StackPanel Background="Red"  VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>

        <Border Grid.Row="1" BorderBrush="Gray" BorderThickness="0,1">
            <wv2:WebView2 Name="WebView" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                              MinWidth="600" MinHeight="800"
                          Source="{Binding Url}"
                          PreviewMouseRightButtonDown="WebView_OnPreviewMouseRightButtonDown"
                          PreviewMouseRightButtonUp="WebView_OnPreviewMouseRightButtonUp"/>
        </Border>
    </Grid>
</UserControl>

Checked Bindings to WebView assembly using Fuslog. All OK.

WebView2 nuget : Microsoft.Web.WebView2 1.0.1020.30

image
image

Hello

As a proof of concept, here is a screenshot of WebView2 working in a .NET plugin loaded into a Delphi host:

There is an issue with WebView2 initialization in Hydra plugins.

Such WebView initialization won’t work due to internal exception in the WebView component:

<wv2:WebView2 Name="webView" 
Source="https://www.google.com/" 
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>

One needs to define component as

<wv2:WebView2 Name="webView" 
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>

and then explicitly set the source during plugin initialization as

        public Plugin()
        {
            InitializeComponent();
            this.Dispatcher.Invoke(() => { this.webView.Source = new Uri("https://remobjects.com"); });
        }

Note that Source is set via Dispatcher.Invoke call.

There is no need to wrap calls to WebView2 properties in other places.

Hope that helps