📜 ⬆️ ⬇️

Free grid control for Xamarin from DevExpress

In the previous article ( Development Features for Xamarin.Forms ) I talked about our development experience for the Xamarin.Forms framework, which allows you to create native user interfaces for three mobile platforms (iOS, Android, Windows Phone) using common C # code and XAML markup .

Today we will look at the result of the work we have done, our first component for Xamarin.Forms - Data Grid. This component can be used for free by downloading here . Together with him you will receive an application that demonstrates the main functionality of the GridControl.


')
So, under the cut you will find an overview of all that the Grid can at the moment, as well as a little Getting Started.


About component


As it should be, our grid is a component for displaying and editing tabular data that can be obtained from sources of various types. Let's see what opportunities it provides for quick and efficient data analysis.

Data management





Columns



Formatting





"Mobile chips"



Most of the above functionality is available to end-users by default. For example, through the built-in context menus (each of which, by the way, can be easily customized if necessary - for example, add new items or delete existing ones) or intuitive gestures. Any of the available functions can also be easily made inaccessible to users, if necessary.

And at the disposal of developers - API, giving them complete freedom of action.

Create application


Well, now let's see how to add a Grid component to the application and start working with it.

So, first we will create a new Xamarin.Forms Portable application in Xamarin Studio (in general, Xamarin.Forms applications can be developed in Visual Studio, but in this example we will use Xamarin Studio on OS X).

Next, download the DevExpress Grid component from the Xamarin Components store and add it to Android and iOS projects. This is done very simply - right in Xamarin Studio.



Please note that when adding a component, links to all the necessary “platform” assemblies are automatically added to Android and iOS projects.



But links to the general assemblies DevExpress.Mobile.Grid.v15.1.dll and DevExpress.Mobile.Core.v15.1.dll need to be added to the PCL project manually. You can find them in the Components / devexpress-grid-15.1.5.0 / lib / pcl / directory, which is automatically created in the current application directory.

If you are working in Visual Studio, and your application includes a Windows Phone project, you must also manually add links to the DevExpress.Mobile.Grid.WinPhone.v15.1.dll and DevExpress.Mobile.Core.WinPhone.v15 assemblies . 1.dll .

To initialize the grid, add the following line to the files MainActivity.cs and AppDelegate.cs (Android and iOS projects, respectively):

DevExpress.Mobile.Forms.Init(); 


Now you can create an instance of the grid, while not forgetting to connect the namespace DevExpress.Mobile.DataGrid .

The data source for the grid is set via the ItemsSource property.

By default, the grid will create columns for all fields from the data source. The set or order of columns in the grid can be changed by setting them manually using the GridControl.Columns property.

Here, for example, how this can be done using XAML markup.

 <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="HelloGrid.MainPage" xmlns:dxg="clr-namespace:DevExpress.Mobile.DataGrid;assembly=DevExpress.Mobile.Grid.v15.1"> <dxg:GridControl x:Name="grid" ItemsSource="{Binding Orders}" SortMode="Multiple" AutoFilterPanelVisibility="true"> <dxg:GridControl.Columns> <dxg:TextColumn FieldName="Product.Name" Caption="Product" Width="170" /> <dxg:NumberColumn FieldName="Product.UnitPrice" Caption="Price" DisplayFormat="C0"/> <dxg:NumberColumn FieldName="Quantity"/> <dxg:NumberColumn FieldName="Total" UnboundType="Integer" UnboundExpression="[Quantity] * [Product.UnitPrice]" IsReadOnly="True" DisplayFormat="C0"/> <dxg:DateColumn FieldName="Date" DisplayFormat="d"/> <dxg:SwitchColumn FieldName="Shipped" /> </dxg:GridControl.Columns> <dxg:GridControl.TotalSummaries> <dxg:GridColumnSummary FieldName="Total" Type="Sum" DisplayFormat= "Total: {0:C0}"/> </dxg:GridControl.TotalSummaries> </dxg:GridControl> </ContentPage> 


In the above code, in addition to the definition of grid columns, we also:


Now when you start the application, we get such a grid filled with data from the specified source.



A small promo video about our GridControl can be viewed here:



Conclusion


Like this. Now in our product line there is also a grid component for the Xamarin platform. If you are looking in the direction of developing mobile applications using Xamarin.Forms technology, then be sure to try our grid - this is easy, it is free and conveniently integrated into your project. We will be happy to answer your questions and hear your wishes in the comments to this article.

Source: https://habr.com/ru/post/264039/


All Articles