设计器生成的 WinForm 中的 INotifyPropertyChanged 用于检测修改的控件
我正在尝试实现一种检测用户何时修改表单的方法,并且我正在尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我可能是错的,但我认为您需要通过 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:
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 callOnComponentChanging
before the change occurs.