c# - How to add a textbox row inside the datagrid wpf
问题描述
I have a Datagrid that binds and auto generate columns. I need to add a row inside the table for searchbox in each column of DataGridTextColumn type alone.
I need to create like this in the photo below
I have searched a lot but i can't find any solution for it. Anyone know how to create the textbox inside datagrid. Some links or sample codes will be helpful.
解决方案
您可以修改ItemsPanel
为其他控件创建间隙:
<DataGrid.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel IsItemsHost="True" Margin="0,50,0,0"/>
</ItemsPanelTemplate>
</DataGrid.ItemsPanel>
然后将其他文本框覆盖到DataGrid
使用 aCanvas
或任何其他ClipToBounds
等于 false的控件的区域上
<Grid>
<DataGrid ItemsSource="{Binding ...}" >
<DataGrid.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel IsItemsHost="True" Margin="0,50,0,0"/>
</ItemsPanelTemplate>
</DataGrid.ItemsPanel>
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding ...}" x:Name="col1"/>
<DataGridTextColumn Binding="{Binding ...}" x:Name="col2"/>
</DataGrid.Columns>
</DataGrid>
<Canvas>
<TextBox Height="30" Width="{Binding ElementName=col1, Path=ActualWidth}" Margin="10,30,0,0"/>
<TextBox Height="30" Width="{Binding ElementName=col2, Path=ActualWidth}" Margin="50,30,0,0"/>
</Canvas>
</Grid>
我将跳过使用转换器将每个文本框的边距绑定到列宽的部分,因为编写代码对我来说完全是微不足道的。
此处的其他解决方法
推荐阅读
- facebook - 无效范围:user_location。一键登录facebook?
- angular - Angular 6 反应形式。如何为多种语言构建表单
- java - 分析核心 java 以检查每个计数器的方法统计信息和延迟
- c++ - 如何包装可变参数模板函数?
- components - 访问模型类实例说“未定义”
- python - Jupyter Lab 未使用虚拟环境
- memory-leaks - IOS系统库导致内存泄漏
- python - 如果 datetime 可以是偏移感知或幼稚的,则从当前时间减去 datetime 对象
- ios - 将文本从 UITextView 发送到另一个类时,UILabel 为 nil
- amazon-web-services - awssdk.s3 抛出 System.MissingMethodException