So I have a UI using XAML and I was thinking about having an embedded Bing Map, or maybe Google Map I'm not sure. It's possible to create an interactive map on the UI, but I need to be able to click pushpins and retrieve data which doesn't seem to be possible without Javascript, so I was wondering if the UI could open up an embedded map, which can easily have pushpin events(such as detecting clicks), and send the data from that pin back to the UI?
-
Which technology do you use? Wpf? Maui? Xamarin? Uno platform? Winui? They all use xaml. – ˈvɔlə Jul 01 '22 at 17:47
-
@ˈvɔlə wpf im pretty sure – Marcus Jul 01 '22 at 20:13
-
How do you embed the map? Any NuGet package? Any code sample? – ˈvɔlə Jul 02 '22 at 16:16
-
Does this answer your question? [How to respond to click event with GMap.net for WPF](https://stackoverflow.com/questions/17549857/how-to-respond-to-click-event-with-gmap-net-for-wpf) – ˈvɔlə Jul 02 '22 at 16:16
-
@ˈvɔlə https://stackoverflow.com/questions/72835496/how-to-receive-a-variable-in-javascript-from-c?noredirect=1#comment128651252_72835496 This is a question I asked about the same problem that has some sample code. – Marcus Jul 05 '22 at 16:45
1 Answers
Bing Maps has two different map controls that can be used in native .NET applications. So no need to embed a JavaScript map.
There is the Windows UWP map SDK that can be used in Windows apps, and in WPF apps via a XAML island. Here are some useful resources:
- https://learn.microsoft.com/en-us/windows/uwp/maps-and-location/
- https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/host-standard-control-with-xaml-islands
There is also an older WPF SDK that has fewer capabilities than the UWP SDK. It is generally recommended to use the UWP map control, but if you want to use this, here are the details: https://learn.microsoft.com/en-us/previous-versions/bing/wpf-control/hh750210(v%3dmsdn.10)
If you really want to embed a JavaScript map into a .NET app and be able to communicate between the two, it can be done. To do that you need to embed a web browser control into your .NET app and then us interop functions to send messages back and forth. This takes a decent amount of work to get working well. Note that if you use the built in .NET browser you cannot float XAML elements above the browser/map (this has been an issue for over a decade). If you embed the chrome browser it is possible to modify it so you can float XAML elements over the browser, but this also makes your app significantly larger.

- 16,570
- 2
- 21
- 46
-
On the UI, I can't add pushpin events on a WPF map, so I added a hyperlink that opens up an html file. https://stackoverflow.com/questions/72835496/how-to-receive-a-variable-in-javascript-from-c?noredirect=1#comment128651252_72835496 I asked this question too, wondering if it's possible to pass data from the UI to the htm file? Someone suggested adding parameters to the URL but I can't seem to get that to work right now. – Marcus Jul 05 '22 at 16:53
-
@rbrundritt I Agree. Using the native WPF control seems like the best choice. – ˈvɔlə Jul 05 '22 at 17:21