[英]WPF Custom datagrid column header
I need to create a Custom dataGrid DataGridTextColumn like the sketch below: 我需要创建一个自定义dataGrid DataGridTextColumn,如下图所示:
The Red rectangles are TextBox and are used to search within the column. 红色矩形是TextBox,用于在列中进行搜索。
so far i have implemented a datagrid like this (simplify 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 have no idea how to create those textBoxes. 我不知道如何创建这些文本框。 Any clue would be appreciate it
任何线索将不胜感激
DataGridTemplateColumn
is what you are looking for. 您正在寻找
DataGridTemplateColumn
。 You can customize the template as per your need - 您可以根据需要自定义模板-
<DataGrid>
<DataGrid.Columns>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBox BorderBrush="Red" BorderThickness="3" Margin="5"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
With sample ItemsSource
it gives this look - 借助示例
ItemsSource
它具有以下外观-
EDIT 编辑
In case you want to customize the header, you need to provide HeaderTemplate
for your column like this - 如果您想自定义标题,则需要像这样为您的列提供
HeaderTemplate
<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 the look - 外观-
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.