FlexGrid for WPF | ComponentOne
C1.WPF.FlexGrid.4.6.2 Assembly / C1.WPF.FlexGrid Namespace / Column Class / CellTemplate Property
Example

In This Topic
    CellTemplate Property (Column)
    In This Topic
    Gets or sets the template used to display the contents of a cell that is not in editing mode.
    Syntax
    'Declaration
     
    Public Property CellTemplate As DataTemplate
    public DataTemplate CellTemplate {get; set;}
    Remarks

    The CellTemplate and CellEditingTemplateproperties work like the equivalent ones in the Microsoft DataGrid for Silverlight/WPF.

    They can be defined in XAML and are used to create the visual elements that represent the cells in the column.

    CellTemplate creates cells in regular mode and CellEditingTemplate creates cells in edit mode.

    Note that in most cases you should specify a Binding for the column even if it has custom templates. The templates are used to show and edit the values on the grid, but the column binding is still used when getting data values for other purposes including clipboard and export support.

    Example
    The XAML below creates a column with custom templates for cell display and editing (notice that in addition to the templates, the XAML specifies a Binding for the column):
    <c1:C1FlexGrid x:Name="_fgTemplated">
      <c1:C1FlexGrid.Columns>
      
        <!-- add a templated column -->
        <!-- Binding used only for clipboard and export support -->
        <c1:Column Binding="{Binding Name}" Header="Template" Width="200">
                
          <!-- template for cells in display mode -->
          <c1:Column.CellTemplate>
            <DataTemplate>
              <TextBlock Text="{Binding Name}" Foreground="Green" FontWeight="Bold" />
            </DataTemplate>
          </c1:Column.CellTemplate>
                
          <!-- template for cells in edit mode -->
          <c1:Column.CellEditingTemplate>
            <DataTemplate>
              <Grid>
                <Grid.ColumnDefinitions>
                  <ColumnDefinition Width="Auto" />
                  <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Image Source="edit_icon.png" Grid.Column="0" />
                <TextBox Text="{Binding Name, Mode=TwoWay}" Grid.Column="1" />
              </Grid>
            </DataTemplate>
          </c1:Column.CellEditingTemplate>
        </c1:Column>
      </c1:C1FlexGrid.Columns>
    </c1:C1FlexGrid>
    See Also