Xamarin.Forms

Upgrade Guide User Guide Demos Support Forums Download
  • Upgrade Guide
  • User Guide
  • Demos
  • Support
  • Forums
  • Download
Class GridTemplateColumn - Xamarin.Forms API Reference | Syncfusion SfDataGrid column that hosts template-specified Content in its cells. ">

    Show / Hide Table of Contents

    Class GridTemplateColumn

    Represents a SfDataGrid column that hosts template-specified Content in its cells.

    Inheritance
    System.Object
    GridColumn
    GridTemplateColumn
    Implements
    System.IDisposable
    Inherited Members
    GridColumn.ColumnSizerProperty
    GridColumn.AllowEditingProperty
    GridColumn.CellStyleProperty
    GridColumn.ActualWidthProperty
    GridColumn.PaddingProperty
    GridColumn.MappingNameProperty
    GridColumn.HeaderTextProperty
    GridColumn.AllowSortingProperty
    GridColumn.FormatProperty
    GridColumn.CultureInfoProperty
    GridColumn.WidthProperty
    GridColumn.HeaderTemplateProperty
    GridColumn.MinimumWidthProperty
    GridColumn.MaximumWidthProperty
    GridColumn.IsHiddenProperty
    GridColumn.AllowFocusProperty
    GridColumn.GroupModeProperty
    GridColumn.SortModeProperty
    GridColumn.HeaderCellTextSizeProperty
    GridColumn.CellTextSizeProperty
    GridColumn.FontAttributeProperty
    GridColumn.RecordFontProperty
    GridColumn.HeaderFontProperty
    GridColumn.HeaderFontAttributeProperty
    GridColumn.TextAlignmentProperty
    GridColumn.HeaderTextAlignmentProperty
    GridColumn.LineBreakModeProperty
    GridColumn.GetFormattedValue(Object)
    GridColumn.SetDisplayBindingConverter()
    GridColumn.Dispose()
    GridColumn.Dispose(Boolean)
    GridColumn.ColumnSizer
    GridColumn.AllowEditing
    GridColumn.CellStyle
    GridColumn.ActualWidth
    GridColumn.LoadUIView
    GridColumn.Padding
    GridColumn.MappingName
    GridColumn.HeaderText
    GridColumn.AllowSorting
    GridColumn.Format
    GridColumn.CultureInfo
    GridColumn.HeaderCellTextSize
    GridColumn.CellTextSize
    GridColumn.FontAttribute
    GridColumn.RecordFont
    GridColumn.HeaderFont
    GridColumn.HeaderFontAttribute
    GridColumn.TextAlignment
    GridColumn.HeaderTextAlignment
    GridColumn.LineBreakMode
    GridColumn.Width
    GridColumn.HeaderTemplate
    GridColumn.ValueBinding
    GridColumn.DisplayBinding
    GridColumn.MinimumWidth
    GridColumn.MaximumWidth
    GridColumn.IsHidden
    GridColumn.GroupMode
    GridColumn.CellType
    GridColumn.SortMode
    GridColumn.AllowFocus
    Namespace: Syncfusion.SfDataGrid.XForms
    Assembly: Syncfusion.SfDataGrid.XForms.dll
    Syntax
    public class GridTemplateColumn : GridColumn, IDisposable
    Remarks

    Use GridTemplateColumn to display the value in the template of your requirement.

    The GridTemplateColumn type enables you to create your own column types by specifying the cell template or cell template selector to use for displaying value. To specify the template that is used to display the contents of a cell, set the CellTemplate property. and to set the template selector, use CellTemplateSelector property.

    Examples
            
                <syncfusion:GridTemplateColumn.CellTemplate>
                  <DataTemplate>
                    <Label Text = "{Binding CustomerID}" 
                           TextColor="Black" 
                           XAlign="Center" 
                           YAlign="Center" />
                  </DataTemplate>
                </syncfusion:GridTemplateColumn.CellTemplate>

    Constructors

    GridTemplateColumn()

    Initializes a new instance of the GridTemplateColumn class.

    Declaration
    public GridTemplateColumn()

    Properties

    CellTemplate

    Gets or sets the template that is used to display the contents of a cell.

    Declaration
    public DataTemplate CellTemplate { get; set; }
    Property Value
    Type Description
    Xamarin.Forms.DataTemplate

    The Xamarin.Forms.DataTemplate that is used to display the contents of a cell.

    Remarks

    SfDataGrid allows the user to customize the GridColumn with your own view by setting the CellTemplate of GridTemplateColumn. To specify the template that is used to display the contents of a cell, set the CellTemplate property.

    Examples
    <syncfusion:SfDataGrid.Columns>
    <syncfusion:GridTemplateColumn MappingName="CustomerID">
        <syncfusion:GridTemplateColumn.CellTemplate>
            <DataTemplate>
                <Label Text = "{Binding CustomerID}" TextColor="Black" 
                       XAlign="Center" YAlign="Center" />
            </DataTemplate>
        </syncfusion:GridTemplateColumn.CellTemplate>
    </syncfusion:GridTemplateColumn>
    </syncfusion:SfDataGrid.Columns>
    See Also
    https://help.syncfusion.com/xamarin/sfdatagrid/column-types#celltemplate

    CellTemplateSelector

    Gets or sets the template selector that selects the template in which the Content of the cell to be displayed.

    Declaration
    public DataTemplateSelector CellTemplateSelector { get; set; }
    Property Value
    Type Description
    Xamarin.Forms.DataTemplateSelector

    The Xamarin.Forms.DataTemplateSelector that selects the template in which the Content of the cell to be displayed.

    Remarks

    SfDataGrid allows the user to customize the GridColumn with your own view by setting the CellTemplateSelector of GridTemplateColumn. When the user wants to select the template between the available templates based on the value in the underlying collection, the user can use this property. The Content of the cell will be displayed in the template selected.

    Examples
       <ContentPage.Resources>
            <ResourceDictionary>
                <DataTemplate x:Key="low" >
                    <Label Text = "{Binding Freight}"
                           TextColor="White" 
                           BackgroundColor="Red" 
                           HorizontalTextAlignment="Center" 
                           VerticalTextAlignment="Center" />
                </DataTemplate>
                <DataTemplate x:Key="average" >
                    <Label Text = "{Binding Freight}"
                           TextColor="Black" 
                           BackgroundColor="Yellow" 
                           HorizontalTextAlignment="Center" 
                           VerticalTextAlignment="Center" />
                </DataTemplate>
                <DataTemplate x:Key="high" >
                    <Label Text = "{Binding Freight}"
                           TextColor="White" 
                           BackgroundColor="Green" 
                           HorizontalTextAlignment="Center" 
                           VerticalTextAlignment="Center" />
                </DataTemplate>
            </ResourceDictionary>
        </ContentPage.Resources>
        <syncfusion:SfDataGrid.Columns>
        <sfgrid:GridTemplateColumn MappingName = "Freight">
            <sfgrid:GridTemplateColumn.CellTemplateSelector>
                <local:FreightTemplateSelector High = "{StaticResource high}"
                                  Average="{StaticResource average}"
                                  Low="{StaticResource low}"/>
        </sfgrid:GridTemplateColumn.CellTemplateSelector>
    </sfgrid:GridTemplateColumn>
    </syncfusion:SfDataGrid.Columns>
    See Also
    https://help.syncfusion.com/xamarin/sfdatagrid/column-types#gridtemplatecolumn

    EditTemplate

    Gets or sets the Xamarin.Forms.DataTemplate to load in editing mode.

    Declaration
    public DataTemplate EditTemplate { get; set; }
    Property Value
    Type Description
    Xamarin.Forms.DataTemplate

    The template that is used to display the contents of cell in a column that is in editing mode. The default is null.

    Remarks

    To specify the template that is used to display the contents of a cell when entering edit mode, set the EditTemplate property.

    Examples
    <syncfusion:SfDataGrid.Columns>
    <syncfusion:GridTemplateColumn MappingName="CustomerID">
        <syncfusion:GridTemplateColumn.EditTemplate>
                <DataTemplate>
                    <Entry Text = "{Binding CustomerID}" />
                </ DataTemplate >
            </ syncfusion:GridTemplateColumn.EditTemplate> 
    </syncfusion:GridTemplateColumn>
    </syncfusion:SfDataGrid.Columns>

    EditTemplateSelector

    Gets or sets the Xamarin.Forms.DataTemplateSelector by choosing a template based on bound data objects and data-bound element in editing mode.

    Declaration
    public DataTemplateSelector EditTemplateSelector { get; set; }
    Property Value
    Type Description
    Xamarin.Forms.DataTemplateSelector

    A custom Xamarin.Forms.DataTemplateSelector object that provides logic and returns a Xamarin.Forms.DataTemplate that is in edit mode of column. The default is null.

    Remarks

    SfDataGrid can customize the GridColumn with any view by setting the EditTemplateSelector of GridTemplateColumn.

    Examples
       <ContentPage.Resources>
            <ResourceDictionary>
                <DataTemplate x:Key="low" >
                    <Label Text = "{Binding Freight}"
                           TextColor="White" 
                           BackgroundColor="Red" 
                           HorizontalTextAlignment="Center" 
                           VerticalTextAlignment="Center" />
                </DataTemplate>
                <DataTemplate x:Key="average" >
                    <Label Text = "{Binding Freight}"
                           TextColor="Black" 
                           BackgroundColor="Yellow" 
                           HorizontalTextAlignment="Center" 
                           VerticalTextAlignment="Center" />
                </DataTemplate>
                <DataTemplate x:Key="high" >
                    <Label Text = "{Binding Freight}"
                           TextColor="White" 
                           BackgroundColor="Green" 
                           HorizontalTextAlignment="Center" 
                           VerticalTextAlignment="Center" />
                </DataTemplate>
            </ResourceDictionary>
        </ContentPage.Resources>
    <syncfusion:SfDataGrid.Columns>
    <sfgrid:GridTemplateColumn MappingName="Freight" >
     <sfgrid:GridTemplateColumn.EditTemplateSelector>
        <local:FreightTemplateSelector High = "{StaticResource high}"
                                       Average="{StaticResource average}"
                                       Low="{StaticResource low}"/>
     </sfgrid:GridTemplateColumn.EditTemplateSelector>
    </sfgrid:GridTemplateColumn>
    </syncfusion:SfDataGrid.Columns>

    Methods

    CanEditCell()

    Determines whether the column is editable.

    Declaration
    protected override bool CanEditCell()
    Returns
    Type Description
    System.Boolean

    Returns true if all the cells with in the column is editable .

    Overrides
    GridColumn.CanEditCell()

    Implements

    System.IDisposable

    See Also

    https://help.syncfusion.com/xamarin/sfdatagrid/column-types#gridtemplatecolumn
    Back to top Generated by DocFX
    Copyright © 2001 - 2022 Syncfusion Inc. All Rights Reserved