Vb.net Mobile Application - vb.net

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.

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:
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.
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).
Right-click the VB.NET project again, click "Manage NuGet Packages", then install Xamarin.Forms.
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
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!

Related

Unable to copy-paste Winforms controls from a form in a vb.net project to a form in a c# project

for a big refactoring project of about 140 forms I've been trying to copy and paste these controls through the designer. I'm using VS 2022 but I've also tried with 2019. The origin project is in .NET4.5 and the new project is in dotnet6. My machine is running on win10.
These are the things I've tried so far:
keyboard shortcuts ( ctrl-a + ctrl-c / ctrl-x + ctrl-v )
Drag 'n drop ( ctrl-a + drag + drop )
Same methods as above but one control at a time ( total size of clip is 164k bytes )
The paste option in the context menu of the c# form is grayed out and when I drag 'n drop I'm shown a "blocking" icon.
I'm at a loss and not about to redesign all these forms.
Am I missing something here?
I just did some testing and it appears that you cannot drag and drop - or copy and paste, presumably - between different instances of VS, which you appear to be trying to do. I opened the same solution twice and I was able to drag and drop between C# and VB projects in the same instance but I wasn't able to do so between two forms in the same VB project between instances.
This means that you will have to add one of the projects to the solution containing the other. That's not a big deal because adding an existing project to a solution doesn't move or copy that project. The solution simply refers to it in its existing location. Once you've done all the drag and drop, you can simply remove the project from the solution again and you're done.
According to this post, .NET framework 4.x is incompatible at the binary level with .NET core which prevents you from copying over controls. Logical really when I come to think about it.
I've tested with dotnet5.0 and dotnet6.0 both giving issues but dotnet4.8 works just fine.
As a solution to my problem I will try using an intermediate project in .NET framework 4.8 using c# and afterwards porting to dotnet6.
Thanks for the help.
You cannot directly copy control from .NET Framework 4.x to .NET6 in winform application, because .NET Framework and .NET6 are different frameworks, so if your project only targets windows, you can consider updating the project to .NET Framework 4.8 which allows you to copy-paste Winforms controls.
In order to convert VB project(.NET Framework) to C# project(.NET6), one of the option is to convert VB code in the InitializeComponent method to C#, and paste it into the same location in .NET 6.
Also check : Upgrade a Windows Forms App to .NET 6 with the .NET Upgrade Assistant
Note: some libraries in .NET Framework are not supported on .NET6, you may need to find their alternatives.

Understanding how Cross-Platform App starts and uses xaml pages

(I have experience with MVC, WebForms, WinForms. I am getting started with Cross-Platform App projects.)
I created a Cross-Platform App project including Xamarin.Forms.
Visual Studio created 4 sub-projects:
"MyProject"
"MyProject".Android
"MyProject".iOS
"MyProject".UWP
I suppose that I actually have to develop most of my project in "MyProject" except for UI specifics things?
Then I have two questions:
Where is it written in "MyProject".UWP that it has to display "MyProject"\MainPage.xaml?
Why can't I view "MyProject"\MainPage.xaml in designer mode?
I think I found both aswers:
Where is it written in "MyProject".UWP that it has to display
"MyProject"\MainPage.xaml?
Somewhere in "MyProject".UWP\MainPage.xaml.cs is the line MainPage = new MyProject.App(); and in "MyProject".UWP\App.xaml.cs is MainPage = new MyProject.MainPage();
(For those not used to work XAML files: the .cs code can be viewder click on the arrow left to the XAML file.)
Why can't I view "MyProject"\MainPage.xaml in designer mode?
According to https://developer.xamarin.com/guides/xamarin-forms/troubleshooting/questions/forms-xaml-designer/
Possible answer: "There is not yet a visual designer for generating XAML in Xamarin.Forms applications, so all XAML must be hand-written."

Is it possible to extract an icon from an old Visual Studio project?

I have an old VB project that I'm converting from WinForms into WPF. I was re-creating the user interface without problems until I tried to locate the Icon that the old application uses. I can't find it in the project files and I can't see a way in visual studio to export it.
Anyone know of a way to accomplish this? I'd like to keep the UI as close to the old UI as possible (users don't like change).
You can extract icon resources from your file. See a free app to do it:
nirsoft.net/utils/resources_extract.html

Is it possible to create a generic base class for user control in XAML for Visual Studio 2012

There seems to be a bit of yes/no/absolutely/no way info floating around on the web about this. I'd like to be able to create a base class.
class GenericUserControl<T> : UserControl {
// Lots of cools stuff based on T cause I wanna! In fact T
// will be the ViewModelClass but please no pedantic discussion on what
// MVVM is or is not. I want generics in XAML!
}
Then create a new concrete user control in the designer based off GenericUserControl
class MyControl : GenericUserControl<MyControlViewModel> {
}
I've seen a number of blog post claiming this is possible using x:TypeArguments in XAML and there seems to be XAML doc http://msdn.microsoft.com/en-us/library/ms750476.aspx suggesting this feature is possible but then again I've found posts saying this feature is broken in Visual Studio 2012.
So if this is possible and any genius can figure out how to get it working specifically with VS 2012 then please post a tested solution here and I will be super happy.
This is possible to do using x:TypeArguments in xaml, but it is known to break the various xaml designers (both inside Visual Studio and Blend).
The problem has been fixed in the Visual Studio 2012 Xaml designer, with the latest CTP of Visual Studio 2012 Update 2.
Discussion:
http://social.msdn.microsoft.com/Forums/en-US/toolsforwinapps/thread/895b38c7-ddde-4d38-8915-493be0efe6a7/
CTP download:
http://www.microsoft.com/en-us/download/details.aspx?id=36539
Unfortunately it does not seem to work in the latest Blend for Visual Studio 2012.

Inspecting XAML in Windows 8 Store Apps / VS2012

I'm looking for a way to inspect running XAML in a Windows 8 store app. Essentially, I want firebug / chrome inspector style functionality where I can look at the XAML source generated at runtime, to debug simple layout and style issues.
I've tried Snoop, Pistachio and WPF Inspector but none work for Windows Store apps. The only one I can find which seems to work for Store apps is XAML Spy, which is €90. I can't justify that cost.
Is there any other way to inspect running XAML?
WinRT XAML Toolkit now has an actual visual - visual tree debugger.
Get it from NuGet: nuget.org/packages/winrtxamltoolkit.Debugging then call WinRTXamlToolkit.Debugging.DC.ShowVisualTree() to display the debugger tool inside of your app. It's the third option so now you can use
the WinRTXAMLToolkit.Debugging.VisualTreeDebugger class - that enables you to debug the tree in your Visual Studio
XAML Spy - which is a great commercial visual tree debugger that runs in a separate window
and now this visual tree debugger in the WinRT XAML Toolkit that works inside of your app.
The VisualTreeDebugger class from WinRT XAML Toolkit is what you could use if you want a free tool. It doesn't do as much as XAML Spy, but you get what you pay for. I thought of adding more features to it like actual visualization of what you debug, but the work required would not justify the time investment + I didn't want to step on Koen Zwikstra's turf. I am sure he is doing a great job on that tool. Anyways - VisualTreeDebugger is enough for me, so maybe it would also be enough for you.
The way you can use it is add the class to your code, add a reference in your XAML like
xmlns:debug="WinRTXamlToolkit.Debugging"
then put a hook on a control where you would like to start debugging, like
debug:VisualTreeDebugger.BreakOnLoaded="True"
which will dump the core visual tree details as text in your debugger output window (Ctrl+W,O) and break in the code that dumped your tree where you can investigate the "path" variable, which contains the list of all visual tree elements from the debugged control to the root, so you can watch their values if what you need wasn't already dumped in the output window.
Other options include
debug:VisualTreeDebugger.BreakOnTap="True"
debug:VisualTreeDebugger.BreakOnLayoutUpdated="True"
debug:VisualTreeDebugger.BreakOnLoaded="True"
debug:VisualTreeDebugger.TraceOnTap="True"
debug:VisualTreeDebugger.TraceOnLayoutUpdated="True"
debug:VisualTreeDebugger.TraceOnLoaded="True"
Since it is source code and really a single simple class - you can easily add additional things to the code to do any custom debugging you need.
XAML Spy is what you need. You find it at http://xamlspy.com.
there is a new free tool called XAML Inspector. It's available through NuGet. Just search for "xamlinspector" or get if from the project page: www.xamlinspector.com
Greetings
Christian