次の方法で共有


Property Change Notification Events 

Property change notification events are used to inform code when a property value changes either through internal or external activity. This allows the code to update related state as necessary (for example, by altering the appearance of a control in the user interface).

Consider raising change notification events when property values in high-level APIs (usually designer components) are modified.

This guideline applies to high-level members where change notification adds significant value to the library. For example, objects that provide or interact with the user interface use change notification to allow dependent UI objects to be updated accordingly. Change notification events should not be used where there is no value added to the library or where notification would be so frequent that it would significantly impact performance. For example, it is incorrect to raise a change notification event each time elements are added or removed from a general purpose collection. To avoid adding unneeded complexity to commonly used types, a special purpose collection should be used when this functionality is required. The .NET Framework version 2.0 libraries provide Collection as a general purpose collection. For collections that require notification, the Framework also provides BindingList.

Consider raising change notification events when the value of a property changes through external forces.

If a property value changes due to some external force such as user input, use a change notification event before the change is made permanent to indicate that the value will be changing. After the change is made permanent, use another event to signal that the value has changed. For example the Control class provides the Validating and Validated events to inform code of control validation.

Portions Copyright 2005 Microsoft Corporation. All rights reserved.

Portions Copyright Addison-Wesley Corporation. All rights reserved.

For more information on design guidelines, see the "Framework Design Guidelines: Conventions, Idioms, and Patterns for Reusable .NET Libraries" book by Krzysztof Cwalina and Brad Abrams, published by Addison-Wesley, 2005.

See Also

Concepts

Indexed Property Design
Property Design

Other Resources

Member Design Guidelines
Design Guidelines for Developing Class Libraries