AnsweredAssumed Answered

How can I create a MapView control that I can consume in an MFC application

Question asked by chrisb_b on Dec 20, 2016
Latest reply on Dec 28, 2017 by mnielsen-esristaff

One can normally host a WPF control in MFC using teh Interop described in like  When I try this I get an exception in RuntimeCoreNet.GeneratedWrappers.CoreWrapperBase.  It appears that the .NET Runtime assumes there is some XAML to initialise the control.  Has anyone successfully hosted a Runtime MapView in an MFC application?


Code snippet:

HWND GetHwnd(HWND parent, int x, int y, int width, int height)
   System::Windows::Interop::HwndSourceParameters^ sourceParams = gcnew    System::Windows::Interop::HwndSourceParameters("MFCWPFApp");
   sourceParams->PositionX = x;
   sourceParams->PositionY = y;
   sourceParams->Height = height;
   sourceParams->Width = width;
   sourceParams->ParentWindow = IntPtr(parent);
   sourceParams->WindowStyle = WS_VISIBLE | WS_CHILD;
   Globals::gHwndSource = gcnew System::Windows::Interop::HwndSource(*sourceParams);

   Globals::gwcMapView = gcnew Esri::ArcGISRuntime::UI::Controls::MapView; // Fails here with
   // Additional information : The type initializer for 'RuntimeCoreNet.GeneratedWrappers.CoreWrapperBase' threw an    exception.

   FrameworkElement^ myPage = Globals::gwcMapView;

   Globals::gHwndSource->RootVisual = myPage;
   return (HWND)Globals::gHwndSource->Handle.ToPointer();