How to display custom user controls on xServer.net map/WPF?

Within this forum we want to offer discussions all around our .NET based Map control including all .Net-language specific questions concerning calls of the xServer-API. Attention: xServer-relevant concepts can be found in further forums such as xRoute or xTour.
Post Reply
User avatar
Bernd Welter
Site Admin
Posts: 2564
Joined: Mon Apr 14, 2014 10:28 am
Contact:

How to display custom user controls on xServer.net map/WPF?

Post 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.

Code: Select all

// add a new Shape Layer
var layer = new ShapeLayer("MyShapes");
formsMap1.Layers.Add(layer);

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.
layer.Shapes.Add(host);
Best regards,
Bernd
Bernd Welter
Technical Partner Manager Developer Components
PTV Logistics - Germany

Bernd at... The Forum,LinkedIn, Youtube, StackOverflow
I like the smell of PTV Developer in the morning... :twisted:
Post Reply