WPF 数据网格 - 列标题与数据行不对齐
我在 WPF 中使用数据网格。这是一个非常简单且基本的实现。我没有使用任何样式。 我创建了一个简单的数据网格:
<dg:DataGrid x:Name="dg" >
</dg:DataGrid>
并用数据填充它:
dg.ItemsSource = " H E L L O W O R L D!".Split();
网格得到正确填充,但网格的列标题是用一些偏移量绘制的。因此,我的数据和标题未对齐。我尝试通过网络搜索此内容,但没有找到任何内容。这似乎是一个简单的实现,适用于除我之外的每个人:(。 谁能告诉我可能出了什么问题吗?我尝试过使用不同的数据集并应用一些样式来测试这一点。
提前致谢。
I am using Datagrid in WPF. This is a very simple and basic implementation. I not using any styles.
I created a simple datagrid :
<dg:DataGrid x:Name="dg" >
</dg:DataGrid>
and populated it with data as:
dg.ItemsSource = " H E L L O W O R L D!".Split();
Grid gets properly populated but the columnheader of the grid is drawn with some offset. Due to this my data and header are mis aligned. I tried searching for this over net but I haven't found anything. This seems to be a straightforward implementation which is working for everyone except me :(.
Can anyone please tell me what might be going wrong? I have tried using different data sets and appyling some style to test this.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看这篇博文。
http://sweux.com/blogs/smoura/index.php/wpf/2009/05/19/wpf-toolkit-datagrid-part-iii-playing-with-datagridcolumns-and-datagridcells /
Check out this blog post.
http://sweux.com/blogs/smoura/index.php/wpf/2009/05/19/wpf-toolkit-datagrid-part-iii-playing-with-datagridcolumns-and-datagridcells/
为了更详细地了解到底发生了什么,这里有一个示例输出,
其中“x”代表空格。数据网格的列标题和单元格未对齐。我没有为我的数据使用任何样式或间距。
如果有人能提出可能出现问题的建议,那就太好了!
谢谢
To give more detail about what exactly is happening, here is a sample output
where 'x' represents blank space. datagrid's column header and the cells are misaligned. I am not using any styling or spacing for my data.
If anyone could suggest what possibly might be going wrong that would be great!
Thanks