我需要创建一个自定义的dataGrid DataGridTextColumn,如下面的草图:
I need to create a Custom dataGrid DataGridTextColumn like the sketch below:
红色矩形为TextBox,用于在列内搜索。
The Red rectangles are TextBox and are used to search within the column.
到目前为止,我已经实现了一个这样的datagrid(简化版本):
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 对于。您可以根据需要自定义模板 -
DataGridTemplateColumn is what you are looking for. 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>使用示例 ItemsSource
编辑
如果您要自定义标题,则需要提供 HeaderTemplate 为您的列这样 -
In case you want to customize the header, you need to provide HeaderTemplate for your column like this -
<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>这是外观 -
更多推荐
WPF自定义datagrid列标题
发布评论