C# WPF datagrid:列数始终等于 0

发布于 2024-07-30 02:02:29 字数 709 浏览 1 评论 0原文

我在 C# 中创建了一个 WPF takelit 数据网格,并在 XAML 中设置了 ItemsSource。 列是自动生成的。

我正在尝试做一个使用 ObservableCollection 的数据网格,非常类似于 网站

在底部,您将找到一个可以下载的示例(这里是 link)

我的问题是我正在尝试更改特定列的某些属性(例如:Datagrid.Columns[index]。属性)但这似乎不起作用,因为列数始终等于 0。因此,我无法使用我想要使用的索引来更改属性,因为 Columns 集合中似乎没有任何内容。 然而在运行时会显示一些列。

那么,列计数怎么可能等于 0?

以及

在我的情况下如何更改特定列的属性?

I have created a WPF tooklit datagrid in C# and the ItemsSource is set in the XAML. The columns are automatically generated.

I am trying to do a datagrid that uses an ObservableCollection, pretty much like what is on this website.

At the bottom you will find a sample that you can download (here is the link)

My problem is that I'm trying to change certain properties of a specific column (example: Datagrid.Columns[index].Property) but this does not seem to work since the the column count is always equal to 0. Therefore, I cannot change the properties by using the index that I want to use because there seems to be nothing in the Columns collection. Yet at runtime there are columns that are displayed.

So, how can it be possible that column count is equal to 0?

and

How can I change the properties of a specific column in my situation?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

ら栖息 2024-08-06 02:02:30

根据多个论坛的经验,如果列是自动生成的,则无法通过 Columns 属性访问它们。 我不知道为什么会这样,但以前就见过这样的情况。

According to several forum experiences, columns aren't accessible via the Columns property if they are autogenerated. I don't know why this is so, but it has been seen before.

以歌曲疗慰 2024-08-06 02:02:30

我终于找到了方法! 列计数等于 0 的原因是因为尚未生成列。 为了更改属性,我必须使用 AutoGenerateColumns 事件并更改其中的属性。

I have finally found how! The reason that the column count equals 0 is because the columns are not yet generated. In order to change the properties I have to use the AutoGeneratedColumns event and change the properties in there.

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