Javatpoint Logo
Javatpoint Logo

Cells in Xamarin.Forms

Xamarin.Forms cell can be added to ListViews and TableViews. A cell is a specialized element which is used for items in a table and describes how the elements in a list should be rendered. The Cell class is driven from Element, from which we can derive VisualElements. A cell itself is not a visual element. It is a template for creating the visual element. The cell is used exclusively with ListView and TableView control.

Here are the types of cell:

  • TextCell
  • SwitchCell
  • EntryCell
  • ImageCell
  • ViewCell

TextCell

TextCell is a cell that has two separate text areas for displaying the data. TextCell is typically used for the purpose of the information in both TableView and ListView controls. The two text areas are aligned vertically to maximize the space within the cell.

Here we want to show the contact details of a person with the help of TextCell in the ListView.

These are the steps that we follow to show the contact details of the person in TextCell.

Example:

In this example, we are creating TextCell in ListView to show the ContactDetail of a person.

// Program

MainPage.XAML

Here, we create a class, which is Data.CS, where we create the data.

Data.CS

On the coding page of the MainPage.Xaml.CS, we create a list of the data, where we provide the information of the person, and then show the information of the object (people) in the TextCell with the help of ListView.

MainPage.Xaml.CS

Execute this program, click on the emulator.

Output:

Cells in Xamarin.Forms

This print the ContactDetail of the Ayesha Tyagi and Vaishali Tyagi

SwitchCell

SwitchCell is a cell that combines the capabilities of a label and an on-off switch. A SwitchCell can be useful for turning on and off the functionality or user preference or configuration options.

Example:

In this example, we are creating a SwitchCell to show the text and functionality of the Switch.

//Program

MainPage.XAML

Output:

Cells in Xamarin.Forms

EntryCell

EntryCell is a cell that combines the capabilities of a Label and Entry. The EntryCell can be useful in those scenarios when we build some functionality in our application to gather the data from the user. They can be easily placed into a TableView and can be treated as simple form.

Example:

Here, we create EntryCell with TableView in Xamarin.Forms application for Android and Universal Window Platform with Xaml in cross-platform application development.

For that, we have to set up the environment for the Cross-Platform application.

Here, we will follow the following steps:

Step1: Right, Click on Project Name, as shown in the Screenshot.

Cells in Xamarin.Forms

Step2: Click on the Properties, as shown in the screenshot.

Cells in Xamarin.Forms

Step3; Check the multiple startup project radio button-> click on apply->click ok.

Cells in Xamarin.Forms

MainPage.Xaml

Execute this program, click on the emulator.

Output:

In Android

Cells in Xamarin.Forms

Here, in the output, this prints the information of a person in the EntryCell in TableView in Android.

Output:

In Windows

Cells in Xamarin.Forms

ImageCell

ImageCell objects are used to place the images and text into a table. ImageCell control the functions similarly to a normal page control.

MainPage.Xaml

Execute this program, click on the emulator.

Output:

Cells in Xamarin.Forms

ViewCell

We can consider the ViewCell as a blank slate. It is our personal canvas to create a cell that looks exactly the way that we want.

With the help of ViewCell, we can do customization of the forms.

Example:

Here, we create a page in the ViewCell with the help of ListView.

//Program

MainPage.Xaml

Class is created where we define the Variable name of items, which we want to show on the page.

//Program

Data.CS

On the coding page of the MainPage.Xaml, we create a list of items with id.

//Program

Execute this program, click on the emulator.

Output:

Cells in Xamarin.Forms

The above program prints the Contact Detail of the Ayesha Tyagi and Vaishali Tyagi with the number of Id.


Next TopicXamarin.Android




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA