Visual Studio + C # + Xamarin = ios/android/windows Apps

Source: Internet
Author: User
Tags email account android sdk manager visual studio 2010

Visual Studio launch War across platforms (1)--Hello xamarin!

The programmed development of the foot, never stopped. From the early Windows applications, to the Web application of the Internet, to the Mobile application, which was prevalent in recent years, the developers of C # and the users of Visual Studio, in addition to the Windows Ph. Does one and the Windows Store app allow you to launch IOS and Android apps with the familiar launch environment of C # and Visual Studio to awaken your soul again? Xamarin is the framework that is born of this demand.

Xamarin Simple

Xamarin was evolved from the early Mono program, originally a open source code for C # programs on Linux. After that, the Mono Touch framework and the mono for Android framework support IOS. So it's not a new product on the market. In 2011, the original Mono team at Novell set up a company to formally change its name to Xamarin as Xamarin. Xamarin has the following features:

  • quickly build native (Native) mobile applications -through C # 's and fully functional language features-with the convenience of the. NET Framework's Base Class Library (BCL). Allows the developers to launch mobile applications with the highest productivity possible. Currently, Mono supports C # 5.0 's language specification, which means that developers can use your familiar Lambda expression,linq or even Async/await's non-synchronous processor.

  • code sharing -the IOS application that was developed by OBJECTIVE-C and the Android application that was developed by Java cannot be shared with code. Xamarin is written in C #, so through a good design, you can share business logically and information access programs on different platforms without having to re-write them. In addition to saving the time cost of re-writing, it is also useful for version maintenance and consistency.

  • integration with Visual Studio –xamarin provides Visual Studio 2010/2012 plug-in, which allows developers who are already familiar with Visual Studio to be familiar with other development tools. When creating a case, you can create a direct set of IOS and Android. Of course, the launch team can also put IOS and Android code into ALM, using Team Foundation Server's version and build management.

  • To ensure that the first time update –xamarin for iOS and Android version updates, in iOS SDK 5.0,6.0 and 6.1, both with Apple on the same day, the Framework version of the response, 7.0 also promise to One day to the table. On the Android side, Xamarin even changed the Android's original code from Java to C #, and the performance has been greatly improved.

  • Native Application Effectiveness –xamarin the translator for IOS and Android platforms. Encode the C # code directly into the ARM CPU's machine password. As a result, the performance will be no different than the native mode of the application. On the Android system, because Xamarin does not use Android's Dalvik virtual machine, it uses the CLR to test its performance more than its native application.

Relative articles
  • Hello Xamarin
  • IOS Basic Control Introduction
  • IOS Multi-page application development
  • Android Basic Control Introduction
  • Android Multi-page application program
System Requirements
  • iOS: Because Apple restricts the IOS app to be encoded by Xcode, it requires a 1 MAC machine as the Build Host:

    • Windows 7 or newer operating system versions
    • Visual Studio 2010/2012
    • OS X Lion or newer operating system version
    • Xcode IDE and IOS SDK
  • Android: For Android, it can be completely done on Windows. The requirements of the system are as follows:

    • Windows 7 or newer operating system versions
    • Java SDK
    • Android SDK
    • Xamarin, Android for Visual Studio
Install Xamarin

Whether you're installing Xamarin on a Windows or MAC, it's easy to download a name and Email account on the As long as you choose the next step of the installation, you can install the Android SDK and other related components.

Windows Installed daylight face:
MAC version of the installed daylight face:

Xamarin is a business Framework, but you can try it for a full 30 days or use a free version. But free version limit the IL code size after the opening is not over K, and cannot be developed using Visual Studio (only Xamarin studio provided by Xamarin).

After you've installed Xamarin, you'll need to register a Xamarin account to activate it.

    1. Open Visual Studio, click Tools-Xamarin Account
    2. If you have previously registered a Xamarin account (please note that the Xamarin account is different from the Email you previously downloaded), please enter your account password directly and if you are using it for the first time, please apply for a new Xamarin account.

      After logging in, you can start developing Android and IOS apps!
Using Visual Studio to launch Android helloworld!

Using Xamarin to develop an Android application can be a convenient way to design a user interface using drag-and-drop in Visual Studio and integrate tools such as AVD and SDK Manager. Don't say much, start our 1th Android program on Visual Studio ~

  1. In Visual Studio, the new case, in the case of the C # section, you will find that the case is more of the Android and IOS type of case, we choose "Android Application" in this example, and in the name of the "Hell ODroid "(Of course you can change to any name you want)
  2. After the project is established, you will find several items in the tool list:

    It is stated as follows (from left to right):
    • Target devices: You can choose which Device to deploy the current project to, and the "Prompt for Devices" preset will pop up the window for the user to choose from when the bug/deployment is started. If a physical device is connected, it will also appear in this list.
    • Device record : You can select a device and display a live record that is currently installed.
    • Open Android virtual Device Manager (AVD)and through this administrator you can add, open or edit Android emulator.
    • Android SDK Manager: because of the Android version (API level), you can install the required SDK version and components on this admin interface.
  3. In the project, a button control is built and the "Hello World,click Me" is written to open the project's Resources-Layout-Main.axml can go to the design of the page.
  4. The main code for this example is Activity1.cs, which is directly explained by the following illustration:

    See this code, I think we should not feel strange. The pen has some students who say to me that it feels like the Windows Form application program seems to be Activity1.cs as the Controller of the MVC layer. Through the Setcontentview method, tell the system which page to load. Then, through the Findviewbyid method, the object of the button on the canvas is obtained. You can then write a code related to the button's nature or method, or handle a button event. As shown in the image above, the example of a preset is to use an anonymous method, and we'll write it using Lambda Expression instead.
  5. Then press F5, you can start to do the wrong, if you do not first open the Android emulator, the Running devices list will be empty, you can click on the bottom of the "Start Emulator image" link to the activation of the simulator.
  6. The results are as follows:

    Is it quite simple? Next we'll start the IOS Hello World.
Using Visual Studio to develop IOS helloworld!

Unlike the launch of Android, Xamarin currently does not support the design of the program page in Visual Studio, but officials say it is currently being developed and will be available in the later versions. So the current UI design for IOS has to be through the MAC's Interface Builder (part of XCode), or the location and size of the controls directly in the program, and HelloWorld in Visual Studio application is to use this method.

  1. Add a new case in Visual Studio, select IPhone under IOS in the case, and select HelloWorld application in the right-hand section, then specify the name of the case (this is Helloios)
  2. The first time you start an iOS application, Xamarin will prompt users to launch iOS in Visual Studio only in the commercial version or later.

    Then Xamarin will automatically activate the grant of the trial version, and after that, it prompts the user that Visual Studio is going to restart.

    If the Xamarin license on your MAC has not yet been initiated, you will see a system prompt stating that the Build Server (that is, MAC) has not yet been granted permissions. When pressing the Activate button at this time may not work, please follow the steps below to activate Xamarin on your MAC.
  3. Because Xamarin is on MAC, it's not a release. Therefore, you can force the use of Xamarin to grant permissions through the following methods. Start the Xamarin Studio in the MAC Finder

    Add a new case, choose IPhone-Single View application. After the establishment of the case, click on the Feature List-Profile-mono

    At this point, you will see the rights-granting screen. When we're done, we can go back to Visual Studio and specify our Build Host.
  4. In Visual Studio's tools-options, you can see a more Xamarin episode, click on IOS Settings under Xamarin, and on the right you can specify Mac Build Host. You can directly enter the computer name or IP address of your MAC or press Configure to set it up.

    In the Settings window, Xamarin searches for MAC machines that have been installed in the same Web segment and have been enabled to use Xamarin. If the status is displayed as "Ready," please press connect.

    If the state is not "ready", you can press the diagnose button to proceed with the diagnostics. As shown in the following illustration, if one or more items cannot be diagnosed by the connection, you will be presented with a failed, and you can open the failed item to understand the cause of the failure.
  5. In group management, the platform is set as Iphonesimulator, which is expected to be deployed to the physical machine, but this requires an Apple to pay the developers account.

    Then in the toolbar, you can select the version of the IOS emulator, the right side of the green tick indicates that the connection with the MAC Build host is normal, if the anti-gray state, please click on the right side of the image to re-connect with the specified Build host.
  6. Open the MyViewConrtoller.cs file in the case. In this case, the same thing is to place a Button control (the category name UIButton in IOS) in the canvas and display the number of points to click. Since we are producing controls in the program, some of the code is declaring the object's layout, please refer to the following code:
  7. Next up is the point of the example program, and if you are designing a UI in XCode, you can replace the program above.

    Like the previous Android HelloWorld, in IOS, the button click event is not called Click, but is touchupinside, so we have the process of this event, after the user click the button, change the button display text (using UIButton Setti Tle method). Finally, the Button control is added to the canvas through the View.addsubview method.

    The results are as follows:
Cross-platform development

As a cross-platform solution, using Visual Studio with the Xamarin launch mobile app has the following features:

      • can include all platforms in the same scenario: includes Windows phone,windows 8 Store App,ios and Android. As shown in the following image:
      • code sharing: in the design, the platform is not related to the business logically, service access, access to information and the information layer from the interface, as shown below:

        Here's how to achieve this integration and code sharing, first look at the structure diagram:

        from the above diagram, we can see that the left side is a common code that can be drawn out, this part will be separate into a single case, and only add common components (such as the Base Class Library), if some of the code used in the platform-related components or technology, you can add the code to the   terms of the instructions, for the direct use of the platform, do not need to modify.

        In the case of each platform, the shared code can be connected to each platform by the way the files are linked. However, since Visual Studio does not provide a way to set up multiple files or folders at the same time, it is actually more realistic if each file has to be linked in a manual. And in the future, the common code case if there are file differences, such as new or deleted. Each platform is not updated synchronously. We can do this by 1 of the expansion functions called "Project Linker 2012" (It also has the version of Visual Studio 2010).

        Once the project Linker is installed, we can click the right mouse key on each platform--Add Project link

        and then select the source, and then you will be connected to each folder and file in the source case.

        The files in Visual Studio will have a blue arrow icon

        After the above setup, you can share the code in each platform program. In the development of the platform, as long as the user interface and PIN to the control of the operation to write a program. For business logically, some of the information access can be shared across platforms, which is not possible using native development methods (Objective-c,java). The following results are actually done:

Visual Studio + C # + Xamarin = ios/android/windows Apps

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.