WPF 数据网格 - 列标题与数据行不对齐

发布于 2024-09-02 01:17:16 字数 403 浏览 1 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

自此以后,行同陌路 2024-09-09 01:17:16

为了更详细地了解到底发生了什么,这里有一个示例输出,

 xxxxxxxxxxxxxxxHeader1              Header2
 xxxxx**Value1**       **Value2**

其中“x”代表空格。数据网格的列标题和单元格未对齐。我没有为我的数据使用任何样式或间距。
如果有人能提出可能出现问题的建议,那就太好了!

谢谢

To give more detail about what exactly is happening, here is a sample output

 xxxxxxxxxxxxxxxHeader1              Header2
 xxxxx**Value1**       **Value2**

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文