How to do it...

  1. Launch Visual Studio for Mac and sign in with your Microsoft Account details. You will notice the Get Started section that lists a number of useful articles that help developers get up and running with Visual Studio for Mac:
  1. Next, click on New Project... and select the Forms App project from the Xamarin.Forms group in the Multiplatform App templates. Then, click on Next:
  1. We then need to give our application a name and an Organization Identifier. I simply called my app HelloWorld and then selected only iOS under Target Platforms. Click on Next to continue:
  1. Lastly, decide whether you want to configure your project to use Git for version control and Xamarin Test Cloud. When you have configured what you need to, click on Create:
  1. When your project is created, you will notice that you can select the device you want to simulate by clicking on the down arrow next to the Debug button:
  1. This will list the different simulators available to you, as well as any devices tethered to your Mac (in this case, my iPhone):
  1. Clicking on the Run button will launch the simulator for the selected device and display the default application created for you when you created the Xamarin.Forms iOS application:
  1. The application in the simulator is fully functional and you can interact with it to get a feel for how the simulator works. As mentioned earlier, if you have an iOS device tethered to your Mac, you can even launch the application on your device to test it. Clicking on the About tab, for example, will display the About page:
  1. Click on the Stop button in Visual Studio for Mac and go back to your solution. Expand the ViewModels and Views folders. You will see a very familiar structure:
  1. In the ViewModels folder, open the AboutViewModel.cs file. In the constructor AboutViewModel(), you will see the following code:
        public AboutViewModel()
{
Title = "About";
OpenWebCommand = new Command(() => Device.OpenUri(new
Uri("https://xamarin.com/platform")));
}
  1. For now, just to illustrate the use of C#, change the code here to look like the following code listing. Do you notice the first line of code? The section after var titleText = is an interpolated string $"Hello World - The date is {DateTime.Now.ToString("MMMM dd yyyy")}";. Interpolated strings were introduced in C# 6.0. Click on the Play button to launch the application in the simulator: 
        public AboutViewModel()
{
var titleText = $"Hello World - The date is {
DateTime.Now.ToString("MMMM dd yyyy")}";
Title = titleText;
OpenWebCommand = new Command(() => Device.OpenUri(new
Uri("https://xamarin.com/platform")));
}
  1. Now, click on the About tab again and look at the title. The title has changed to display Hello World and the current date:
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.124.21