This guide explains how to show a LuciadCPillar map in a C# WPF application.
Adding the map control
The LuciadCPillar C# samples provide a ready-to-use WPF control, WpfMapControl (namespace
Luciad.Integration.Wpf, in the integration_wpf sample library). It is sample integration code rather than
part of the SDK: copy the integration_wpf project from the samples and reference it, as the sample applications do.
WpfMapControl is a WPF UserControl. Add it to your window and set its DataContext to a
WpfMapControlViewModel that holds your MapMapMap:
<Window xmlns:wpf="clr-namespace:Luciad.Integration.Wpf;assembly=Luciad.CPillar.CSharp.Integration.Wpf">
<wpf:WpfMapControl DataContext="{Binding WpfMapControlViewModel}" />
</Window>
where your window’s view model exposes WpfMapControlViewModel = new WpfMapControlViewModel { Map = map }.
Call Destroy() on the control when the hosting window closes, to release its GPU resources.
High-resolution (HiDPI) display handling
WpfMapControl reads the display scale and DPI from WPF (VisualTreeHelper.GetDpi) and configures them on the
map automatically, including when the window moves to a display with a different scale.
Event handling
WpfMapControl forwards mouse, wheel, keyboard and touch input to the
MouseGestureRecognizerMouseGestureRecognizerMouseGestureRecognizer and
TouchGestureRecognizerTouchGestureRecognizerTouchGestureRecognizer, which turn raw events into the
high-level gestures that the active IControllerIControllerIController consumes. This happens
out of the box: set Map.Controller and the control routes input to it. WPF expresses screen coordinates in
device-independent pixels, so you do not need to scale event coordinates.
WinForms and the legacy approach
For a WinForms application, use ViewControl (namespace Luciad.Integration.WinForms) from the same
integration_wpf sample library instead: new ViewControl { Map = map }. It renders with a WebGPU swapchain on
the control’s window handle.
A WinForms ViewControl can also be hosted in a WPF application through a WindowsFormsHost. That is the
approach the D3DImage-based WpfMapControl replaced. It is subject to the airspace limitation though,
which means it’s not possible to add any WPF components on top of the map component.