设计器生成的 WinForm 中的 INotifyPropertyChanged 用于检测修改的控件

发布于 2024-11-06 12:22:07 字数 477 浏览 8 评论 0原文

我正在尝试实现一种检测用户何时修改表单的方法,并且我正在尝试使用 INotifyPropertyChanged (INPC) 接口来执行此操作。但是,我使用 Visual C# Express Designer 来管理所有表单元素。

我在互联网上见过很多关于如何通过创建自己的类(具有自己的成员字段和控件)来使用 INPC 的示例,但迄今为止我从未见过 INPC 示例,其中他们将此接口合并到 .designer 中。 cs(生成)控件将允许检测设计器生成的控件何时被修改。

有没有这样的例子,或者实际上会是什么样子?网上有这方面的例子吗?

:-( 我已经被这个问题困扰了一段时间了。如果有人能给我帮助那就太好了

。PS 我无法使用 Control.Textchanged 事件,因为当用户在 SelectedIndexChanged 期间更改控件所在的 TabControl 中的选项卡时,Binding.Format() 和 Binding.Parse() 会发出误报。

I'm trying to implement a way of detecting when a form has been modified by the user, and I'm trying to use the INotifyPropertyChanged (INPC) interface to do it. But, I'm using the Visual C# Express Designer to manage all of the form elements.

I've seen plenty of examples of how to use the INPC by creating your own class with its own member fields and controls on the internet, but I've never to date seen an INPC example where they incorporate this interface into the .designer.cs (generated) controls that would allow detecting when those Designer-generated controls have been modified.

Is there an example of this, or what would this look like practically? Are there any online examples of this?

:-( I've been struggling with this problem for a while now. If anyone at all can give me a help up that would be wonderful.

P.S.
I can't use the Control.Textchanged event because Binding.Format() and Binding.Parse() send off false positives when the user changes tabs in the TabControl the controls are in during SelectedIndexChanged.

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

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

发布评论

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

评论(1

枕梦 2024-11-13 12:22:07

我可能是错的,但我认为您需要通过 IComponentChangeService 让设计者知道更改。在您的自定义控件中,当发生更改时,您可以使用以下代码来获取更改服务:

IComponentChangeService changeService = this.GetService(typeof(IComponentChangeService)) as IComponentChangeService;

然后您可以对其调用OnComponentChanged,传递必要的信息。我认为如果您希望撤消正常工作,您还应该在更改发生之前调用 OnComponentChanging

I could be wrong, but I think you need to go through the IComponentChangeService to let the designer know about changes. In your custom Control, when a change occurs, you can use the following code to get the change service:

IComponentChangeService changeService = this.GetService(typeof(IComponentChangeService)) as IComponentChangeService;

Then you can call OnComponentChanged on it, passing off the necessary information. And I think if you want undo to work correctly, you are also supposed to call OnComponentChanging before the change occurs.

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