Giter Site home page Giter Site logo

elsoncosta / xamarin-gridview Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kishandonga/xamarin-gridview

0.0 0.0 0.0 10.75 MB

Xamarin Forms GridView developed on the basis of the adapter pattern so easily we can bind custom grid view with data it also behave data grid for same check examples.

License: GNU General Public License v3.0

C# 100.00%

xamarin-gridview's Introduction

Xamarin Forms GridView


Xamarin Forms GridView no longer maintain anyone can fork and publish as NuGet Package


More screenshots:
GridView with images
GridView with alphabet characters
GridView as DataGrid - 1
GridView as DataGrid - 2

This is Android Adapter Pattern GridView in the Xamarin Forms, which simply takes your list of the data and convert into the grid pattern as like in android. you just need to pass the item count and root view of your cell.

Installation

This GridView code added into your xamarin form project and rebuild project. For, the more information refer this XamGridView sample project.

Usage

Here's an example of code to write custom adapter class of the GridView and how to use adapter pattern in the xamarin forms. You can see the complete code sample here:

Custom adapter class of the GridView which is extende the abstract class GridAdapter and need to implements this three methods. You can see the code of this file here:

public class ImagesGridAdapter : GridAdapter	
{    
    private List<string> lstImages;    

    public ImagesGridAdapter(List<string> lstImages)    
    {    
        this.lstImages = lstImages;    
    }    

    public override int GetCount()    
    {    
        return lstImages.Count;    
    }    

    public override object GetItem(int position)    
    {    
        return lstImages[position];    
    }    

    public override View GetView(int position, View convertView, View parentView)    
    {    
        ImagesGridViewHolder holder;    

        if (convertView == null)    
        {    
            holder = new ImagesGridViewHolder();    
            convertView = holder.getRootView();    
            convertView.BindingContext = holder;    
        }    
        else    
        {    
            holder = (ImagesGridViewHolder)convertView.BindingContext;    
        }    

        //.....    

        return convertView;    
    }    
}    

Xamarin does not have layout inflater facility so, need to manually write grid cell code which is our view holder class. You can see the code of this file here:

public class ImagesGridViewHolder
{
    public Image img;

    public ImagesGridViewHolder()
    {
        img = new Image();
        img.Aspect = Aspect.Fill;
    }

    // To get the root view of the your cell
    public View getRootView()
    {
        return img;
    }
}

XAML:

First add the xmlns namespace:

xmlns:grid="clr-namespace:DLab.Views;assembly=DLab.GridView"

Then add this sample xaml code:

<StackLayout>
    <grid:GridView x:Name="gridLayout" 
          NumColumns="3" 
          ScrollToEnd="False" 
          Padding="5,5,5,5" />
</StackLayout>
ImagesGridAdapter adapter = new ImagesGridAdapter(lstImages);
// always first initialize tap event then after pass the item source
gridLayout.ItemTapped += Handle_TapEvent;
gridLayout.ItemSource = adapter;

Event:

private void Handle_TapEvent(object s, GridEventArgs arg)
{
    Device.BeginInvokeOnMainThread(() =>
    {
        // get the selected view holder from the Event arguments
        // arg.view.BindingContext => to get the ViewHolder
        // arg.position
    });
}

Bindable Properties

Properties Version Description
NumColumns 1.0 How many columns are required, minimum 1 and default 3
ScrollToEnd 1.0 If true then automatically scrolling view else not, default false
ColumnSpacing 1.0 To give the space between two column, default 6.0
RowSpacing 1.0 To give the space between two row, default 6.0

Update GridView

It does not follow the observing pattern so when you do change in your list, you need to notify view using this methods NotifyDataSetChanged() or NotifyDataSetChanged(int position). For, more information refer this code sample here:

Small Print

Current issues

  • GridView cell not support animations when initialize
  • If TapEvent initialize after ItemSource then it is consider as null so, event not detects

Contributing

Contributions are welcome! If you find a bug please report it and if you want add new feature then please suggest to me. If you want to contribute code please file an issue and create a branch off of the current dev branch and file a pull request.

About me

Kishan Donga (@ikishan92)
I am android developer so that's why I develope this GridView in the adapter pattern.

License

Xamarin-GridView is released under the GPU license.

xamarin-gridview's People

Contributors

kishandonga avatar kdsyno avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.