Bindable UserControl stops updating when an event member is added

Bindable UserControl stops updating when an event member is added

Old forum URL: forums.lhotka.net/forums/t/11692.aspx


Troncho posted on Friday, November 09, 2012

[System.ComponentModel.DefaultBindingProperty("InfoObj")]

[DefaultEvent("InfoObjChanged")]

public partial class UCNrgHelpBase : UserControl

{

public event EventHandler<NrgHelpBaseEventArgs> InfoObjChanged;


   public virtual IReadOnlyInfo InfoObj {...}


 

...

}

If I comment the event (InfoObjChanged), DataBinding works perfectly well.

If I just leave the event (InfoObjChanged) decleared,

even without using it anywhere, the control's bindable property

updates just fine but the DataSource property never gets updated.

Do you know what I may be missing here?

Thanks,

 

Troncho

Troncho replied on Saturday, November 10, 2012

I found the problem!

It seems that, behind the curtains, when you declare a class with the attribute:

[System.ComponentModel.DefaultBindingProperty("InfoObj")]

It generates some hidden event for DataBinding handling or something with the following name: [PropertyName + "Changed"].

So, when I declared the

public event EventHandler<NrgHelpBaseEventArgsInfoObjChanged;

it seems to suppress the underlaying behaivour for DataBinding to work correctly.

Just fooling around, I begun changing EventHandler types and names, and I got it working.

The result being that I only changed my custom event handler's name to:

public event EventHandler<NrgHelpBaseEventArgsInfoObj_ValueChanged;

And it all fall into place. Now DataBinding is working again just fine and my custom event is firing just as well.

So, problem seems to be solved.

Troncho

Copyright (c) Marimer LLC