Gets or sets the cell template selector.

Namespace: Dapfor.Wpf.Controls
Assembly: Dapfor.Wpf (in Dapfor.Wpf.dll) Version: 4.1.0.26317 (4.1.0.26317)

Syntax

C#
public DataTemplateSelector CellTemplateSelector { get; set; }
Visual Basic
Public Property CellTemplateSelector As DataTemplateSelector
	Get
	Set
Visual C++
public:
property DataTemplateSelector^ CellTemplateSelector {
	DataTemplateSelector^ get ();
	void set (DataTemplateSelector^ value);
}
F#
member CellTemplateSelector : DataTemplateSelector with get, set

Property Value

Type: DataTemplateSelector
The cell template selector.

Remarks

Different data templates can be set in different columns. These templates are applied to all cells of the column where a template is set. However, sometimes you need to use different templates for different rows. For this purpose Column class provides Column.CellTemplateSelector property that can be used to set a data template selector in run-time. An example of data template selector usage is shown below:

 Copy imageCopy
class CustomTemplateSelector : DataTemplateSelector
{
    public DataTemplate Template1 { get; set; }
    public DataTemplate Template2 { get; set; }
    public override DataTemplate SelectTemplate(object item, DependencyObject container)
    {
        var cell = item as Cell;
        if (cell != null)
        {
            return cell.Row.VisibleIndex == 2 ? Template2 : Template1;
        }
        return base.SelectTemplate(item, container);
    }
}
 Copy imageCopy
<Window.Resources> 
  <TestApplication:MyCollection x:Key="someCollection" /> 
  <TestApplication:IntToFlagValueConverter x:Key="intToFlagConverter"/> 
  <BitmapImage x:Key="image" UriSource="/Images/dapfor.ico" DecodePixelWidth="16" DecodePixelHeight="16" /> 

  <!--Data Template 1--> 
  <DataTemplate x:Key="Template1"> 
    <Grid> 
       <Image Source="{Binding Path=Value, Converter={StaticResource intToFlagConverter}}"/> 
       <Grid Grid.Column="1"> <Ellipse Fill="Green"/> 
         <TextBlock Text="{Binding Path=Text}" HorizontalAlignment="Center" Foreground="Red"/> 
       </Grid> 
       <Grid.ColumnDefinitions> 
         <ColumnDefinition Width="Auto"/> 
         <ColumnDefinition/> 
       </Grid.ColumnDefinitions> 
     </Grid> 
   </DataTemplate> 

   <!--Data Template 2--> 
   <DataTemplate x:Key="Template2"> 
     <StackPanel Orientation="Horizontal"> 
       <Image Source="{StaticResource image}"/> 
       <Image Source="{StaticResource image}"/> 
       <TextBlock Text="{Binding Path=Text}" Margin="5,0,5,0"/> 
       <Image Source="{StaticResource image}"/> 
       <Image Source="{StaticResource image}"/> 
     </StackPanel> 
   </DataTemplate> 


   <!--DataTemplate selector--> 
   <TestApplication:CustomTemplateSelector x:Key="tempateSelector" 
                                           Template1="{StaticResource Template1}" 
                                           Template2="{StaticResource Template2}"/> 
</Window.Resources> 

<df:GridControl Name="grid" ItemsSource="{StaticResource someCollection}"> 
  <df:GridControl.Headers> 
    <df:Header> 
      <df:Header.Columns> 
        <df:Column Id="Value1" Title="Column 0" CellTemplateSelector="{StaticResource tempateSelector}" Width="100" /> 
        <df:Column Id="Value2" Title="Column 1" Width="100" /> 
      </df:Header.Columns> 
    </df:Header> 
  </df:GridControl.Headers> 
</df:GridControl>

See Also