From the course: Building Serverless Xamarin Apps with Azure
Create a new Xamarin.Forms app
From the course: Building Serverless Xamarin Apps with Azure
Create a new Xamarin.Forms app
- [Instructor] Let's start with creating a new Xamarin forms app for Visual Studio for Mac. On the start page, click the new project button and in the dialog that comes up, find the multi-platform section and under that, the app section. Here you see multiple templates for Xamarin forms apps but also for traditional Xamarin apps and even some templates specifically for games. We're going to use the blank forms app and click next. In the next screen, we have to fill out some details for our app. The app name and organizational identifier will act as the unique identifier in the App Store. Let's fill in explorer, California as the app name. And the identifier is already correct. Then we can choose which platforms we want to support. You can see we can choose from Android and iOS. If we do this on Windows, we could also get UWP. Lastly, you can select your code sharing strategy. With .net standard, you will get a physically separated DLL file that's shareable between this project as well as other projects, like your back end project. A shared project is nothing more than a folder that is in a central place and gets compiled into your actual apps. Both can do the exact same thing, but I feel like the .net standard option is cleaner. Click next. And choose what to name your project and where to save it. I'm going to stick with the default settings here. After we click create, Visual Studio will generate our new app for us. First, let's have a look at the project structure in the solution explorer. Here you can see we have a solution with three projects. Our shared .net standard library, and a project for Android and iOS. While Xamarin forms allows us to create cross-platform apps from a single code base, we still need separate projects to bootstrap the app for each platform. The shared project is where you will want to have the majority of your code. When you have your code in there, this means you share it over all platforms. At some point, you can't get around the fact that you will have to write some platform-specific code in the platform project. For instance, the user feature that is only available on that platform. If we look at the iOS project, you can see there are some iOS-specific files and folders in there. For example, the info.plist file is very specific to iOS, and holds all the metadata about your app. The equivalent on Android would be the AndroidManifest.xml file. So you see, while you are creating a cross platform app based on .net, you will still have to have some knowledge of each platform. Let's go back to our shared library. Here you find the app.xaml, and app.xaml.cs file. This is the entry point of our Xamarin forms app. If you go into the xaml.cs file, you can see different life cycle events that are hooked into their platform specific equivalents. I mentioned earlier you can create your UI in C# or xaml. Both have the same capabilities, but I prefer xaml. Here you see the app's main page. It consists of a content page on the highest level, and then contains a stack layout. There are other layout elements, like for example, a grid. A page can have at most one layout element. Inside that element, you can nest other layout elements which allows you to create complex UIs. Inside the stack layout, we can see a label with a simple text. If we run this app on Android, you will see a blank page just showing that label as you would expect to look on Android. If we stop the debugging session, and go over to iOS, we see the same thing. Here we switch over to the iOS project and you'll see that we select a iOS simulator automatically and we simply press the run button again, and it will start the iOS simulator with the exact same code, but now showing you the same page as you would expect it to look like on iOS. This is the power of Xamarin forms. Write once, run everywhere. This will be the starting point of our app.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.