I've run the MapView.cs file through a VB converter but the result fails on Me.Children.Add(_map). as it's undeclared or inaccessible The Code is ..
#If WINDOWS_PHONE_APP ThenImports Windows.UI.Xaml.Controls.MapsImports Windows.UI.Xaml.MediaImports Windows.UI.Xaml.ShapesImports Windows.UI.Xaml#Elif WINDOWS_APP ThenImports Bing.Maps#End IfNamespace App3 Public Class MapView Inherits Grid#If WINDOWS_APP Then Private _map As Map #Elif WINDOWS_PHONE_APP Then Private _map As MapControl#End If Public Sub New()#If WINDOWS_APP Then Private _map = New Map() #Elif WINDOWS_PHONE_APP Then Private _map = New MapControl()#End If Me.Children.Add(_map) End Sub End ClassEnd Namespace
#If WINDOWS_PHONE_APP ThenImports Windows.UI.Xaml.Controls.MapsImports Windows.UI.Xaml.MediaImports Windows.UI.Xaml.ShapesImports Windows.UI.Xaml#Elif WINDOWS_APP ThenImports Bing.Maps#End IfNamespace App3 Public Class MapView Inherits Grid#If WINDOWS_APP Then Private _map As Map #Elif WINDOWS_PHONE_APP Then Private _map As MapControl#End If Public Sub New()#If WINDOWS_APP Then _map = New Map() Me.Children.Add(_map) #Elif WINDOWS_PHONE_APP Then _map = New MapControl() Me.Children.Add(_map)#End If End Sub End ClassEnd Namespace
Also consider using a more OOP like approach. Use the strategy pattern instead of conditional compilation.
Create your own IMap interface. Derive two classes MapPhone and MapApp from it. Use an IoC container to inject the correct map "strategy".
Then your code becomes much more cleaner and easier to read. E.g. (untested)
Namespace App3 Public Class MapView Inherits Grid Private _map As IMap Public Sub New() _map = IoC.Resolve(Of IMap)() Me.Children.Add(_map) End Sub End ClassEnd Namespace
There are a few strange things in your code. These damn converters always do bad things, even for simple code. You are always better to rewrite the code, specially when it is so short.
The variable is declared both at the class level and in the constructor????
The variable is declared as Private in the constructor. You cannot do that. Only Dim and Static are accepted inside a method. And because it is already declared at the class level, you do not need to declare it in there, simply call the constructor as shown by MlandaT.
As for the conditional compilation, do you see parts of the code in color or is almost everything grey? If the 2 clauses of your conditions both show in grey, then something is wrong with your setup. You might have copied you code in the wrong type of project, in which case the conditional compilation variables are not defined.
MlandaT's suggestion has fixed the Add(_map) error but I do have grey code every where.
Any ideas James ?
Jacques Bourgeois (James Burger)
If you look at the project in the Solution Explorer, do you see (Universal Windows) besides the name of the project?
If not, then you are not in a Universal project and the constants are not defined. Simply create a new project by making sure that you are selecting a Universal Windows project as the project template.
Waterside
ASKER
Yes it's Universal. But I have no template for VB.net so I had to add the Win8.1 and WP8.1 projects.
Open in new window