开发者

INotifyPropertyChanged in Designer-Generated WinForm for Detecting Modified Controls

开发者 https://www.devze.com 2023-03-05 07:16 出处:网络
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# Expres

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 co开发者_StackOverflow中文版ntrols 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消