views:

7

answers:

0

How to best utilize the new Type Equivalance features to host the MapPoint Control in a WPF Application.

This is related to my other question about what is entailed as far as maintaining interop assembleis with regard to the new NoPIA and Type Equivalance features. But now I'm interested in actually getting a working implementation to show off how this could be used with regard to the MapPoint Control ActiveX control.

I was able to follow the advice about ensuring that the Embed Introp Types option in Visual Studio is set to True for my MapPoint reference and I'm able to compile and run code like the following within my WPF application which interestingly treats the MapPoint.MappointControl interface as if it has a constructor.

private void Window_Loaded(object sender, RoutedEventArgs e)
{
    var map = new MapPoint.MappointControl();

    if (map.ActiveMap == null)
    {
        map.NewMap(MapPoint.GeoMapRegion.geoMapNorthAmerica);
    }
}

This code seems to work so I'm guessing that the COM calls are all happening properly behind the scenes but the problem is getting this ActiveX control integrated into the control heirarcy for my Window. When using the older ActiveX introp methodologies from Windows Forms I would normally have the generated ActiveX control host which represents my ActiveX control but is also a Windows Forms Control as well which allowed me to host it within a Form or within a WindowsFormsHost in a WPF application. From my research so far it looks like I may be able to host the MapPoint Control directly in WPF by creating a class that inherits from the HwndHost class. This however seems like it may be a lot of work duplicating what the Windows Forms methodology used to generate within the interop assembly for free. My assumption was that with the new Type Equivalence features that we would be able to not only instantiate controls but also integrate these controls directly within a WPF or a Windows Forms app with little trouble as well.

Am I missing something? If not what is the most sane way to go about making use of the MapPoint Control in a WPF app? I'm hoping the answer is not to still have Visual Studio or the TlbImp.exe utility generate the old interop assemblies that we had been using in Windows Forms development.

By the way, I did find some details about different methods of importing a type library but I don't quite understand how it may apply to my situation.

related questions