Created
May 15, 2017 09:58
-
-
Save cdm/3c566fd97a433151c0a2879386455a1b to your computer and use it in GitHub Desktop.
Xamarin Forms GridExtensions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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