Microsoft.Toolkit.Mvvm.ComponentModel Namespace
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Classes
AlsoNotifyChangeForAttribute |
An attribute that can be used to support ObservablePropertyAttribute in generated properties. When this attribute is used, the generated property setter will also call OnPropertyChanged(String) (or the equivalent method in the target class) for the properties specified in the attribute data. This can be useful to keep the code compact when there are one or more dependent properties that should also be reported as updated when the value of the annotated observable property is changed. If this attribute is used in a field without ObservablePropertyAttribute, it is ignored. In order to use this attribute, the containing type has to implement the INotifyPropertyChanged interface and expose a method with the same signature as OnPropertyChanged(String). If the containing type also implements the INotifyPropertyChanging interface and exposes a method with the same signature as OnPropertyChanging(String), then this method will be invoked as well by the property setter. This attribute can be used as follows:
And with this, code analogous to this will be generated:
|
INotifyPropertyChangedAttribute |
An attribute that indicates that a given type should implement the INotifyPropertyChanged interface and have minimal built-in functionality to support it. This includes exposing the necessary event and having two methods to raise it that mirror OnPropertyChanged(PropertyChangedEventArgs) and OnPropertyChanged(String). For more extensive support, use ObservableObjectAttribute. This attribute can be used as follows:
|
ObservableObject |
A base class for objects of which the properties must be observable. |
ObservableObject.TaskNotifier |
A wrapping class that can hold a Task value. |
ObservableObject.TaskNotifier<T> |
A wrapping class that can hold a Task<TResult> value. |
ObservableObjectAttribute |
An attribute that indicates that a given type should have all the members from ObservableObject generated into it, as well as the INotifyPropertyChanged and INotifyPropertyChanging interfaces. This can be useful when you want the same functionality from ObservableObject into a class that already inherits from another one (since C# doesn't support multiple inheritance). This attribute will trigger the source generator to just create the same APIs directly into the decorated class. This attribute can be used as follows:
And with this, the same APIs from ObservableObject will be available on this type as well.
|
ObservablePropertyAttribute |
An attribute that indicates that a given field should be wrapped by a generated observable property. In order to use this attribute, the containing type has to implement the INotifyPropertyChanged interface and expose a method with the same signature as OnPropertyChanged(String). If the containing type also implements the INotifyPropertyChanging interface and exposes a method with the same signature as OnPropertyChanging(String), then this method will be invoked as well by the property setter. This attribute can be used as follows:
And with this, code analogous to this will be generated:
|
ObservableRecipient |
A base class for observable objects that also acts as recipients for messages. This class is an extension of ObservableObject which also provides built-in support to use the IMessenger type. |
ObservableRecipientAttribute |
An attribute that indicates that a given type should have all the members from ObservableRecipient generated into it. This can be useful when you want the same functionality from ObservableRecipient into a class that already inherits from another one (since C# doesn't support multiple inheritance). This attribute will trigger the source generator to just create the same APIs directly into the decorated class. For instance, this attribute can be used to easily combine the functionality from both ObservableValidator and ObservableRecipient, by using ObservableValidator as the base class and adding this attribute to the declared type. This attribute can be used as follows:
And with this, the same APIs from ObservableRecipient will be available on this type as well.
To avoid conflicts with other APIs in types where the new members are being generated, constructors are only generated when the annotated type doesn't have any explicit constructors being declared. If that is the case, the same constructors from ObservableRecipient are emitted, with the accessibility adapted to that of the annotated type. Otherwise, they are skipped, so the type being annotated has the respondibility of properly initializing the Messenger property. Additionally, if the annotated type inherits from ObservableValidator, the SetProperty<T>(T, T, Boolean, String) overloads will be skipped as well, as they would conflict with the SetProperty<T>(T, T, Boolean, String) methods. |
ObservableValidator |
A base class for objects implementing the INotifyDataErrorInfo interface. This class also inherits from ObservableObject, so it can be used for observable items too. |