Suma 2.0

Using the Visual Studio integrated development environment and the C# programming language, we will develop a cross-platform mobile application to find the sum of two numbers.

Start

  1. Launch the Visual Studio integrated development environment.

  2. Create a new project: Visual C# > Cross-Platform > Mobile App (Xamarin.Forms).

  3. Name the project: Suma 2.0.

MainPage.xaml

The MainPage.xaml file contains the source code for the application's user interface design and is written in XAML. Copy (Ctrl+C) and paste (Ctrl+V) the fragment below into your application.

<!-- User Interface (UI): Suma 2.0 -->
<StackLayout Padding="20">

        <!-- Title -->
        <Label Text="Suma 2.0" FontSize="Large" />

        <!-- A -->
        <Label Text="A=" />
        <Entry x:Name="boxA" Keyboard="Numeric" />

        <!-- B -->
        <Label Text="B=" />
        <Entry x:Name="boxB" Keyboard="Numeric" />

        <!-- A+B -->
        <Label Text="A+B=" />
        <Entry x:Name="boxAB" Keyboard="Numeric" />

        <!-- Button -->
        <Button Text="Sum" Clicked="OnButtonClicked" />

</StackLayout>

MainPage.xaml.cs

The MainPage.xaml.cs file contains the source code for the application's business logic and is written in C#. Copy (Ctrl+C) and paste (Ctrl+V) the fragment below into your application.

Demo

Run the application from the menu: Debug > Start Debugging or by pressing the F5 key.

Fig. 2.57 Testing the cross-platform mobile application for finding the sum of two numbers - Android Emulator 11 (API 30)

Last updated