Class GridTemplateColumn
Represents a column that contains template-specified cell content
Inheritance
Inherited Members
Namespace: Syncfusion.UI.Xaml.DataGrid
Assembly: Syncfusion.Grid.WinUI.dll
Syntax
public class GridTemplateColumn : GridTextColumnBase, IDisposable, INotifyDependencyPropertyChanged, IFilterDefinition
Constructors
GridTemplateColumn()
Initializes a new instance of the GridTemplateColumn class.
Declaration
public GridTemplateColumn()
Fields
EditTemplateProperty
Identifies the EditTemplate dependency property.
Declaration
public static readonly DependencyProperty EditTemplateProperty
Field Value
Type |
---|
Microsoft.UI.Xaml.DependencyProperty |
Remarks
The identifier for the EditTemplate dependency property.
EditTemplateSelectorProperty
Identifies the EditTemplateSelector dependency property.
Declaration
public static readonly DependencyProperty EditTemplateSelectorProperty
Field Value
Type |
---|
Microsoft.UI.Xaml.DependencyProperty |
Remarks
The identifier for the EditTemplateSelector dependency property.
HorizontalAlignmentProperty
Identifies the HorizontalAlignment dependency property.
Declaration
public static readonly DependencyProperty HorizontalAlignmentProperty
Field Value
Type |
---|
Microsoft.UI.Xaml.DependencyProperty |
Remarks
The identifier for the HorizontalAlignment dependency property.
Properties
EditTemplate
Gets or sets the Microsoft.UI.Xaml.DataTemplate to load in editing mode.
Declaration
public DataTemplate EditTemplate { get; set; }
Property Value
Type | Description |
---|---|
Microsoft.UI.Xaml.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
The SetCellBoundValue decides whether the data context of the EditTemplate is based on Record or Syncfusion.UI.Xaml.DataGrid.Renderers.DataContextHelper class.
By default, Record will be the DataContext for template. If SetCellBoundValue is true, Syncfusion.UI.Xaml.DataGrid.Renderers.DataContextHelper will be the data context.
Examples
<syncfusion:SfDataGrid x:Name="dataGrid"
AutoGenerateColumns="False"
ItemsSource="{Binding Orders}">
<syncfusion:SfDataGrid.Columns>
<syncfusion:GridTemplateColumn MappingName="CustomerID">
<syncfusion:GridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding CustomerID}" />
</DataTemplate>
</syncfusion:GridTemplateColumn.CellTemplate>
<syncfusion:GridTemplateColumn.EditTemplate>
<DataTemplate>
<TextBox Text="{Binding CustomerID, Mode=TwoWay}" />
</DataTemplate>
</syncfusion:GridTemplateColumn.EditTemplate>
</syncfusion:GridTemplateColumn>
</syncfusion:SfDataGrid.Columns>
</syncfusion:SfDataGrid>
See Also
EditTemplateSelector
Gets or sets the Microsoft.UI.Xaml.DataTemplate 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 |
---|---|
Microsoft.UI.Xaml.Controls.DataTemplateSelector | A custom Microsoft.UI.Xaml.Controls.DataTemplateSelector object that provides logic and returns a Microsoft.UI.Xaml.DataTemplate that is in edit mode of column. The default is null. |
Examples
public class CustomEditTemplateSelector : DataTemplateSelector
{
protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
{
if (item == null)
return null;
var data = item as OrderInfo;
if (data.OrderID % 2 == 0)
return Appliaction.Current.Resources["AlternateEditTemplate"] as DataTemplate;
else
return Application.Current.Resources["DefaultEditTemplate"] as DataTemplate;
}
}
<Page.Resources>
<local:CustomEditTemplateSelector x:Key="editTemplateSelector" />
</Page.Resources>
<syncfusion:SfDataGrid x:Name="dataGrid"
AutoGenerateColumns="False"
ItemsSource="{Binding Orders}">
<syncfusion:SfDataGrid.Columns>
<syncfusion:GridTemplateColumn MappingName = "OrderID"
EditTemplateSelector="{StaticResource editTemplateSelector}"/>
</syncfusion:SfDataGrid.Columns>
</syncfusion:SfDataGrid>
See Also
HorizontalAlignment
Gets or sets the horizontal alignment for the column .
Declaration
public HorizontalAlignment HorizontalAlignment { get; set; }
Property Value
Type | Description |
---|---|
Microsoft.UI.Xaml.HorizontalAlignment | One of the Microsoft.UI.Xaml.HorizontalAlignment enumeration that specifies the horizontal alignment of the column. The default value is Microsoft.UI.Xaml.HorizontalAlignment.Stretch. |
Methods
CanEditCell(Int32)
Determines whether the cells in GridTemplateColumn can be edited.
Declaration
protected override bool CanEditCell(int rowIndex = -1)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | rowIndex | The corresponding rowIndex of the editable cell. |
Returns
Type | Description |
---|---|
System.Boolean | Returns true if the template column has loaded with EditTemplate or EditTemplateSelector. If the GridTemplateColumn loaded with CellTemplate ,returns false. |
Overrides
CanFocus()
Determines whether the GridTemplateColumn can receive focus.
Declaration
protected override bool CanFocus()
Returns
Type | Description |
---|---|
System.Boolean | Returns true if the column is loaded with editor in its CellTemplate. |
Overrides
OnEditTemplateChanged(DependencyObject, DependencyPropertyChangedEventArgs)
Dependency call back for EditTemplate property. Invoked when the EditTemplate dependency property value changed in the GridTemplateColumn.
Declaration
public static void OnEditTemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.UI.Xaml.DependencyObject | d | The |
Microsoft.UI.Xaml.DependencyPropertyChangedEventArgs | e | The Microsoft.UI.Xaml.DependencyPropertyChangedEventArgs that contains the data for the EditTemplate property changes. |
OnEditTemplateSelectorChanged(DependencyObject, DependencyPropertyChangedEventArgs)
Dependency call back for EditTemplateSelector property. Invoked when the EditTemplateSelector dependency property value changed in the GridTemplateColumn.
Declaration
public static void OnEditTemplateSelectorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.UI.Xaml.DependencyObject | d | The |
Microsoft.UI.Xaml.DependencyPropertyChangedEventArgs | e | The Microsoft.UI.Xaml.DependencyPropertyChangedEventArgs that contains the data for the EditTemplateSelector property changes. |
SetDisplayBindingConverter()
Sets the converter for the DisplayBinding of GridTemplateColumn.
Declaration
protected override void SetDisplayBindingConverter()
Overrides
Remarks
You can override this method to specify the converter for DisplayBinding.
UpdateBindingBasedOnAllowEditing()
Updates the binding for the AllowEdit property changes in the GridTemplateColumn.
Declaration
protected override void UpdateBindingBasedOnAllowEditing()