How to display custom user controls on map/WPF?

Within this forum we want to offer discussions all around our .NET based xServer controls.

How to display custom user controls on map/WPF?

Postby Bernd Welter » Mon Oct 08, 2018 12:03 pm

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,
Bernd Welter
Manager Technical Consulting & Requirement Engineering
Senior Technical Consultant Developer Components
PTV GROUP - Germany

Bernd at Youtube
User avatar
Bernd Welter
Site Admin
Posts: 1179
Joined: Mon Apr 14, 2014 10:28 am

Return to PTV xServer.NET (Admin=OH)