Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
923 views
in Technique[技术] by (71.8m points)

datatable - WinForms: Why does databinding break if adding an event with "Changed" suffix?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you are defining RelatedProgramsChanged, you should also fire that event when the property value changes. You have not shown enough code to pinpoint the failure point in your implementation.

The PropertyNameChanged event was the way to signal a change before the introduction of the INotifyPropertyChanged Interface. For more information see: Property-Changed Events.

From the Remarks section of INotifyPropertyChanged:

For change notification to occur in a binding between a bound client and a data source, your bound type should either:

  • Implement the INotifyPropertyChanged interface (preferred).

  • Provide a change event for each property of the bound type.

Do not do both.

This event along with the ShouldSerializePropertyName and ResetPropertyName (see: Defining Default Values with the ShouldSerialize and Reset Methods) methods are retrieved by the property descriptor used by the WinForm binding mechanism. You can inspect the propery descriptor code at ReflectPropertyDescriptor and read the comments to learn more.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...