I'm trying to use some webbrowser in my WPF application so I can show a map from OpenStreetMap.
I've implemented it in my http page the simplest way and it works normally when I open it with Edge, Chrome etc.
But when I try to open it inside WPF using the control WebView2, firstly it tells me that JavaScript was blocked due to security. Then I click on the message and allow it to run. But then it shows 2 javaScript errors popups, and my map doesn't appear in my page.
I've tried the same using WebBrowser control but the same behavior happens.
My wpf has only this:
XAML:
<Window x:Class="RST_Mini_Simulator_WPF.MainWindow"
xmlns=";
xmlns:x=";
xmlns:d=";
xmlns:mc=";
xmlns:local="clr-namespace:RST_Mini_Simulator_WPF" xmlns:wpf="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Button x:Name="btn" Click="btn_Click">DoIt</Button>
<wpf:WebView2 Grid.Row="2" x:Name="webView"></wpf:WebView2>
</Grid>
</Window>
C# code:
using Microsoft.Web.WebView2.Wpf;
using System.Windows;
namespace RST_Mini_Simulator_WPF
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
WebView2 webView = new WebView2();
}
private void btn_Click(object sender, RoutedEventArgs e)
{
webView.NavigateToString("c:/mapPage/index.htm");
}
}
}
My Page code:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="/[email protected]/dist/leaflet.css" />
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div id="map"></div>
<script src="/[email protected]/dist/leaflet.js"></script>
<script src="scripts.js"></script>
</body>
</html>
CSS:
#map{
width:100%;
height:100vh;
}
JavaScript:
let mapOptions = {
center:[-19.9129, -43.9409],
zoom:12
}
let map = new L.map('map',mapOptions);
let layer = new L.TileLayer('http://{s}.tile.openstreetmap/{z}/{x}/{y}.png');
map.addLayer(layer);
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744972084a4604025.html
评论列表(0条)