WPat Custom datagrid column header

I need to create a custom DataGridTextColumn DataGridText, as the sketch below:

Sketch

The red rectangles are a TextBox and are used to search in a column.

so far I have implemented such a data set (simplify the version):

<DataGrid x:Name="CompassLogDataGrid" Grid.Row="1" Style="{DynamicResource ResourceKey=DataGridStyle}" IsTextSearchEnabled="True"> <DataGrid.Columns> <DataGridTextColumn CellStyle="{StaticResource IdCell}" x:Name="ID" Header="ID" Foreground="Black" Binding="{Binding ID}" DisplayIndex="0" /> <DataGridTextColumn x:Name="DateGTC" Header="Date" Binding="{Binding DateString}" CellStyle="{StaticResource DateGTCCell}" /> </DataGrid.Columns </DataGrid 

I do not know how to create these text fields. Any key would be appreciated.

+6
source share
1 answer

DataGridTemplateColumn is what you are looking for. You can customize the template to suit your needs -

  <DataGrid> <DataGrid.Columns> <DataGridTemplateColumn> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBox BorderBrush="Red" BorderThickness="3" Margin="5"/> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> </DataGrid.Columns> </DataGrid> 

With the ItemsSource sample, it gives this view -

enter image description here

EDIT

If you want to customize the header, you must provide a HeaderTemplate for your column, for example:

  <DataGrid> <DataGrid.Columns> <DataGridTextColumn Binding="{Binding Name}" Header="{Binding HeaderName}"> <DataGridTextColumn.HeaderTemplate> <DataTemplate> <StackPanel> <TextBlock Text="{Binding Content, RelativeSource= {RelativeSource Mode=TemplatedParent}}" Margin="5"/> <TextBox BorderBrush="Red" BorderThickness="3" Width="50" Margin="5"/> </StackPanel> </DataTemplate> </DataGridTextColumn.HeaderTemplate> </DataGridTextColumn> </DataGrid.Columns> </DataGrid> 

Here's a look -

enter image description here

+23
source

All Articles