WPF Webview's IsPrivateNetworkClientServerCapabilityEnabled ignored when using ItemTemplate

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



WPF Webview's IsPrivateNetworkClientServerCapabilityEnabled ignored when using ItemTemplate



This simple way of doing is working fine



If I use a WebView, put IsPrivateNetworkClientServerCapabilityEnabled to true, and load a local network website, it will load properly.


IsPrivateNetworkClientServerCapabilityEnabled


true


<WPF:WebView Source="http://localnetworkwebsite"
NavigationStarting="Wvc_NavigationStarting"
NavigationCompleted="Wvc_NavigationCompleted"
IsPrivateNetworkClientServerCapabilityEnabled="True" />



This way of doing is NOT working



In my application, I want to manage several webpage simultaneously (like tabs on a standalone browser), so I use an ItemControl to instantiate the WebView's count I need (this number is not always the same).


ItemControl


<ItemsControl x:Name="ItemsWebview" ItemsSource="Binding WebviewsDataSource">

<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid></Grid>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>

<ItemsControl.ItemTemplate>
<DataTemplate>

<!--Item-->
<WPF:WebView Visibility="Binding Visibility" Source="Binding Source"
NavigationStarting="Wvc_NavigationStarting"
NavigationCompleted="Wvc_NavigationCompleted"
IsPrivateNetworkClientServerCapabilityEnabled="True" />
<!--End Item-->

</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>



And then, I change the Source of ths WebView, and hide/make them visible using the ViewModel:


Source


public class WebviewViewModel : INotifyPropertyChanged

public event PropertyChangedEventHandler PropertyChanged;

public Guid LinkedId get; set;

private System.Windows.Visibility _visibility;
public Visibility Visibility

get

return _visibility;


set

_visibility = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Visibility)));



private Uri _source;
public Uri Source

get

return _source;


set

_source = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Source)));





WebviewsDataSource is ObservableCollection<WebviewViewModel>


WebviewsDataSource


ObservableCollection<WebviewViewModel>



The whole thing seems to works, but ONLY for the external websites, not for the local one. I always get an 404 NotFound for the local network sites when using this ways for creating WebViews, as if IsPrivateNetworkClientServerCapabilityEnabled was ignored. But the local site works with the simple method.


404 NotFound


IsPrivateNetworkClientServerCapabilityEnabled



I've checked the states of the WebViews after the creation, and the IsPrivateNetworkClientServerCapabilityEnabled value is still to true.


IsPrivateNetworkClientServerCapabilityEnabled


true



So...



Since this control is relatively new, this looks like a bug to me...
But am i doing something wrong?



Edit



Minimal .sln of the problem can be downloaded here.


.sln



This simple WPF application will fail to open local network website in ItemTemplate (while external site will works), and will succeed to open local network websites when using the control directly.


ItemTemplate



Just change the WebviewsDataSource value in MainWindowViewModel.cs to test local network urls.


WebviewsDataSource


MainWindowViewModel.cs




1 Answer
1



Microsoft team confirmed this as a bug: https://github.com/Microsoft/WindowsCommunityToolkit/issues/2356



Edit: The bug has been fixed and merged in the v4.0.0. If you experience this problem, you just need to update the Microsoft.Toolkit.Win32.UI.Controls nuget package to 4.0.1+


Microsoft.Toolkit.Win32.UI.Controls






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS