【发布时间】:2011-12-18 15:10:15
【问题描述】:
我正在 WPF 中构建一个应用程序以满足自定义需求。首先我选择了自定义控件,但后来发现我需要的大部分内容已经在 Datagrid Control 中实现了。但是有一个小故障:
Datagrid 的问题在于它强制在两个连续的单元格(网格线的每一侧各 1 个)之间至少有 2 个像素间隙。为了清楚起见,请看下图:
。 请注意两个连续单元格之间的 Datagrid 强制执行的 2 像素间隙: http://img265.imageshack.us/img265/3545/figurem.png
(堆栈溢出不允许我在我的问题中添加图片,引用针对新用户的垃圾邮件保护政策)
.
这不符合我的要求,因为我希望内容显示为“连续”(不能有 2 个像素的间隙;我希望连接线看起来“连接”)。我尝试过使用 GridLinesVisibility,但它没有帮助。 DataGrid 托管了一个这样的自定义控件:
<DataGrid.Columns>
<DataGridTemplateColumn Width="25" Header="">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ContentControl Content="{Binding Path=MyCustomControl}" Margin="0"></ContentControl>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
....
</DataGrid.Columns>
到目前为止我已经尝试过:
- 关闭 GridLine(查看结果:http://img263.imageshack.us/img263/8602/figure2j.png)
- 将内容属性的边距设置为 0。
- 搜索 google 和 stackoverflow
- 查阅了一些书籍。
但似乎什么都没有发生。
是否有解决此/一些 hack 或解决方法的方法,或者我必须从头开始创建所有内容?我在 c# 方面有不错的经验,但我是 WPF 新手。
请帮忙。
【问题讨论】:
标签: wpf datagrid cells gaps-in-visuals