Belf
Belf

Reputation: 47

Vb.net Mobile Application

I've been assigned a school project in which we're asked to develop a survey app for device/mobile use using VB.net. I've started learning some Visual Basic, yet I'm failing to understand the following. I've downloaded Visual Studio 2017, do I need to download something extra so that I'm able to program for a mobile device? Or what is it that I need to do? I'm quite confused, I'd really appreciate some sort of help with understanding what's going on.

I've been searching on the Internet quite some time now, and all I've found is "Visual Basic for Windows Phone Developer Tools - RTW", which is a version for 2010 and I'm not quite sure if it's what I need anyway. Another thing I've found is Xamarin.

Any help will be highly appreciated and excuse me for such a dumb question.

Upvotes: 0

Views: 1866

Answers (1)

TheWitheredStriker
TheWitheredStriker

Reputation: 41

You're probably looking for Xamarin. It lets you use C#, F# and VB.NET code to develop cross-platform apps including native apps for iOS and Android.

Note that Xamarin doesn't completely or directly support VB.NET. You'll have to do the following steps to get started:

  1. Create a new C# solution of the type Mobile App (Xamarin.Forms). You need to have the Mobile Development with .NET workload installed for this.
  2. In said solution, add a Visual Basic .NET Class Library (.NET Standard). After creating the project, right-click it, click Properties, and change the Default Namespace to match the existing C# project(s).
  3. Right-click the VB.NET project again, click "Manage NuGet Packages", then install Xamarin.Forms.
  4. After this, you will want to rename Class1.vb to App.vb. Paste the following starter / example code there:
Imports Xamarin.Forms

Public Class App
    Inherits Application

    Public Sub New()

        Dim label = New Label With {
            .HorizontalTextAlignment = TextAlignment.Center,
            .FontSize = Device.GetNamedSize(NamedSize.Medium, GetType(Label)),
            .Text = "Welcome to Xamarin.Forms with Visual Basic.NET"
        }

        Dim stack = New StackLayout With {
            .VerticalOptions = LayoutOptions.Center
        }

        stack.Children.Add(label)

        Dim page = New ContentPage
        page.Content = stack
        MainPage = page

    End Sub

End Class
  1. Update the Android and iOS projects so that they reference the Visual Basic .NET project(s), rather than the C# project created by the template. Right-click on the References node in the Android and iOS projects to open the Reference Manager. Untick the C# library and tick the Visual Basic .NET library instead. Do this for both iOS and Android. Finally, delete the C# project. You can now develop your Xamarin project in VB.NET by adding more .vb files as necessary.

Unfortunately, VB.NET has a few limitations in regards to Xamarin:

  • You can't write custom renderers or dependency service implementations in VB.NET. These must be written in C# or F#.
  • You can't include XAML pages in VB.NET projects. You'll have to use a workaround that involves including XAML pages in a seperate, C#-based, portable class library, referencing it, and populating the XAML models with VB.NET through databinding. Alternatively, this may be of help for using XAML with VB.NET.

More info can be found at Microsoft's website.

I know this question is three years old, and that lots of time has passed since that school project, but I hope this answer was helpful to you regardless, and / or that it will be helpful to others who have the same or a similar question. To anyone about to write Xamarin apps in VB.NET or who is currently doing so, I wish you the best of luck!

Upvotes: 1

Related Questions