Page 1 of 1

How to display custom user controls on map/WPF?

PostPosted: Mon Oct 08, 2018 12:03 pm
by Bernd Welter
Hi there,

these days a customer wanted to display custom symbols (incl. tooltips) on the xServer.NET control. Unfortunately his approach to display System.Windows.Controls.UserControl objects haven't been successful and so he asked me for an example for hiw WPF implementation.

Well, here's feedback from Oli:
It is possible to use the WindowsFormsHost-class to add any forms control / map control into the map. But I do not recommend that. Check the code below. Another approach would be to add elements OnTop of a map (e.g. for a map legend). Read this article, too.

csharp code
// add a new Shape Layer
var layer = new ShapeLayer("MyShapes");

var point = new Point(8.4, 49);

// Create the interop host control.
System.Windows.Forms.Integration.WindowsFormsHost host =
new System.Windows.Forms.Integration.WindowsFormsHost();

// Create the MaskedTextBox control.
MaskedTextBox mtbDate = new MaskedTextBox("00/00/0000");

// Assign the MaskedTextBox control as the host control's child.
host.Child = mtbDate;

// set location
ShapeCanvas.SetLocation(host, point);

// Add the interop host control to the shape layer's
// control's collection of child controls.

Best regards,