更新 PropertyGrid

发布于 2024-09-07 01:22:54 字数 350 浏览 0 评论 0原文

当 SelectedObject 属性中的对象发生更改时,如何让属性网格自动更新?我尝试在我的类中实现 INotifyPropertyChanged 但属性网格实际上并没有在后台显示对象的新属性,直到我单击它。

我尝试直接订阅对象的 PropertyChanged 事件,并在调用时调用 PropertyGrid 的 Refresh() 方法。但我的一些财产是相关的。这意味着更改一个属性可能会引发多个 PropertyChanged 事件。这似乎工作正常,但我仍然想知道是否有更干净的方法通过数据绑定来执行此操作。另外,我想避免在用户仅更新单个属性后多次刷新控件。

那么有没有办法让PropertyGrid从PropertyChanged事件中刷新呢?

How can I have a property grid update automatically when the object in its SelectedObject property changes? I've tried implementing INotifyPropertyChanged in my class but the property grid does not actually show the new propertyies of the object in the background until I click on it.

I've tried subscribing to the PropertyChanged event of my object directly, and calling the Refresh() method of the PropertyGrid when it is envoked. But some of my properties are related. Meaning changing one property may evoke multiple PropertyChanged events. This seems to work fine, but I'm still wondering if there is a cleaner way of doing this through DataBinding. Also I'd like to avoid having the control Refresh multiple times after the user only updated a single property.

So is there a way to get the PropertyGrid to refresh from PropertyChanged events?

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

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

发布评论

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

评论(2

一枫情书 2024-09-14 01:22:54

尝试将 RefreshProperties 属性添加到具有依赖项的每个属性:

[RefreshProperties(RefreshProperties.All)]

现在,每次此属性更改时 - 它都会自动刷新其他字段。
与每次调用属性网格的“Refresh()”相比,这是一种更简洁的方法。

Try adding the RefreshProperties attribute to each property that has dependencies:

[RefreshProperties(RefreshProperties.All)]

Now, each time this property changes - it will automatically refresh the other fields.
This is a much cleaner approach than calling the property-grid's "Refresh()" each time.

成熟的代价 2024-09-14 01:22:54

我不知道是否有内置方法可以做到这一点,但如果您想避免多次调用相关属性的 Refresh ,这里有一个建议:

PropertyChanged事件发生,启动定时器。如果该事件在计时器到期之前再次发生,则不执行任何操作。在计时器的 Tick 事件中,刷新 PropertyGrid 并停止计时器

I don't know if there's a built-in way to do it, but here's a suggestion if you want to avoid multiple calls to Refresh for related properties :

When a PropertyChanged event occurs, start a timer. If the event occurs again before the timer has elapsed, do nothing. In the Tick event of the timer, refresh the PropertyGrid and stop the timer

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