c# - DataGrid 作为自定义 UserControl
问题描述
我正在尝试创建自己的 DataGrid,它可以像普通 DataGrid 一样构建,但具有一些额外的功能,例如过滤。
它应该采用 DataGridColumns fx 的类型。数据网格文本列。
构建我自己的原因是因为它将在多个视图中使用,但具有不同的列类型和不同的属性。
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<local:MyDataGrid Grid.Row="0" GridItems="{Binding GetArtifactMdls}">
<local:MyDataGrid.Columns>
<DataGridTextColumn Binding="{Binding Name}" />
</local:MyDataGrid.Columns>
</local:MyDataGrid>
<DataGrid Grid.Row="1" ItemsSource="{Binding GetArtifactMdls}">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Name}" />
</DataGrid.Columns>
</DataGrid>
</Grid>
如果有人可以指导我或创建一个快速样本,将不胜感激。
此致
解决方案
通过创建 DataGrid 固有的自定义控件并使用 DataGrid 模板解决了这个问题。通过右键单击设计视图中的 DataGrid 并选择编辑模板获取模板。
推荐阅读
- python - 带有控制台日志记录的 RotatingFileHandler
- swift - 3D 模型在 Xcode 中使用 ARKit 不稳定
- ios - 数据更改后刷新视图
- javascript - 'Vue.js' 父子间通信错误
- python - 如何在 Python 中写入空文件之前检查条件?
- java - 将本地文件夹复制到 SMB 服务器文件夹
- python - 熊猫,根据产品分类确定利润率
- artificial-intelligence - 贪心搜索算法
- css - 如何将 css 应用于垂直居中的元素(wordpress)?
- python - Python:如何查找列中的哪些值在另一个特定列(数据框)中具有 NaN 值