Skip to content

Instantly share code, notes, and snippets.

@cdm
Created May 15, 2017 09:58
Show Gist options
  • Save cdm/3c566fd97a433151c0a2879386455a1b to your computer and use it in GitHub Desktop.
Save cdm/3c566fd97a433151c0a2879386455a1b to your computer and use it in GitHub Desktop.
Xamarin Forms GridExtensions
using System;
using Xamarin.Forms;
namespace cdm.xamarin.forms
{
/// <summary>
/// Easily add grid rows and columns with this extension class
/// </summary>
public static class GridExtensions
{
public static void AddChild(this Grid grid, View view, int row, int column, int rowspan = 1, int columnspan = 1)
{
if (row < 0)
throw new ArgumentOutOfRangeException("row");
if (column < 0)
throw new ArgumentOutOfRangeException("column");
if (rowspan <= 0)
throw new ArgumentOutOfRangeException("rowspan");
if (columnspan <= 0)
throw new ArgumentOutOfRangeException("columnspan");
if (view == null)
throw new ArgumentNullException("view");
Grid.SetRow((BindableObject)view, row);
Grid.SetRowSpan((BindableObject)view, rowspan);
Grid.SetColumn((BindableObject)view, column);
Grid.SetColumnSpan((BindableObject)view, columnspan);
grid.Children.Add(view);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment