C# 클래스 Catel.MVVM.ViewModelBase

View model base for MVVM implementations. This class is based on the ModelBase, and supports all common interfaces used by WPF.
This view model base does not add any services. The technique specific implementation should take care of that (such as WPF, Silverlight, etc).
상속: ModelBase, IViewModel, INotifyableViewModel, IRelationalViewModel, IUniqueIdentifyable
파일 보기 프로젝트 열기: Catel/Catel 1 사용 예제들

Private Properties

프로퍼티 타입 설명
Cancel Task
CancelAndCloseViewModel Task
CancelViewModel Task
Close Task
CloseViewModel Task
DeserializeFromTombstoning void
INotifyableViewModel void
INotifyableViewModel void
INotifyableViewModel void
IRelationalViewModel void
Initialize Task
InitializeModelInternal void
InitializePropertiesWithAttributes void
InitializeThrottling void
InitializeViewModel Task
InitializeViewModelMetaData Catel.MVVM.ViewModelMetadata
OnChildViewModelClosed void
OnChildViewModelPropertyChanged void
OnClosed void
OnClosing void
OnModelErrorInfoUpdated void
OnModelPropertyChangedInternal void
OnThrottlingTimerTick void
PrepareForTombstoneStateInternal void
RecoverFromTombstoneStateInternal void
Save Task
SaveAndCloseViewModel Task
SaveViewModel Task
SerializeForTombstoning byte[]
UninitializeModelInternal void
UninitializeThrottling void
ValidateViewModelToModelMappings void
ViewModelBase System

공개 메소드들

메소드 설명
CancelViewModelAsync ( ) : Task

Cancels the editing of the data.

CloseViewModelAsync ( bool result ) : Task

Closes this instance. Always called after the Cancel of Save method.

InitializeViewModelAsync ( ) : Task

Initializes the view model. Normally the initialization is done in the constructor, but sometimes this must be delayed to a state where the associated UI element (user control, window, ...) is actually loaded. This method is called as soon as the associated UI element is loaded.

It's not recommended to implement the initialization of properties in this method. The initialization of properties should be done in the constructor. This method should be used to start the retrieval of data from a web service or something similar. During unit tests, it is recommended to manually call this method because there is no external container calling this method.

SaveViewModelAsync ( ) : Task

Saves the data.

ToString ( ) : string

Converts the object to a string.

ValidateViewModel ( bool force = false, bool notifyChangedPropertiesOnly = true ) : bool

Validates the specified notify changed properties only.

This method is useful when the view model is initialized before the window, and therefore WPF does not update the errors and warnings.

보호된 메소드들

메소드 설명
CancelAsync ( ) : Task

Cancels the editing of the data.

CloseAsync ( ) : Task

Closes this instance. Always called after the Cancel of Save method.

GetAllModels ( ) : object[]

Gets all models that are decorated with the ModelAttribute.

GetChildViewModels ( ) : IEnumerable

Gets the child view models of this view model.

InitializeAsync ( ) : Task

Initializes the view model. Normally the initialization is done in the constructor, but sometimes this must be delayed to a state where the associated UI element (user control, window, ...) is actually loaded. This method is called as soon as the associated UI element is loaded.

It's not recommended to implement the initialization of properties in this method. The initialization of properties should be done in the constructor. This method should be used to start the retrieval of data from a web service or something similar. During unit tests, it is recommended to manually call this method because there is no external container calling this method.

InitializeModel ( string modelProperty, object model ) : void

Called when a model initialized.

InitializeViewModelAttributes ( ) : void

Initializes the view model attributes, such as the ModelAttribute and ViewModelToModelAttribute. This method is automatically invoked by the constructor. Sometimes, dynamic properties are registered after the constructor. Therefore, it is possible to skip the initialization of the attributes and handle this manually.

IsModelRegistered ( string name ) : bool

Determines whether a specific property is registered as a model.

OnClosedAsync ( bool result ) : Task

Called when the view model has just been closed. This method also raises the Closed event.

OnClosingAsync ( ) : Task

Called when the view model is about to be closed. This method also raises the Closing event.

OnModelPropertyChanged ( object sender, PropertyChangedEventArgs e ) : void

Called when a property on one of the registered models has changed.

This method will also raise for properties that are not mapped on the view model.

OnPropertyChanged ( AdvancedPropertyChangedEventArgs e ) : void

Called when a property value has changed.

OnValidated ( IValidationContext validationContext ) : void

Called when the object is validated.

OnValidating ( IValidationContext validationContext ) : void

Called when the object is validating.

OnValidatingBusinessRules ( IValidationContext validationContext ) : void

Called when the object is validating the business rules.

OnValidatingFields ( IValidationContext validationContext ) : void

Called when the object is validating the fields.

OnViewModelCommandExecuted ( IViewModel viewModel, ICatelCommand command, object commandParameter ) : void

Called when a command for a view model type that the current view model is interested in has been executed. This can be accomplished by decorating the view model with the InterestedInAttribute.

OnViewModelEvent ( IViewModel viewModel, ViewModelEvent viewModelEvent, EventArgs e ) : void

Called when an event for a view model type that the current view model is interested in has been raised. This can be accomplished by decorating the view model with the InterestedInAttribute.

OnViewModelPropertyChanged ( IViewModel viewModel, string propertyName ) : void

Called when a property has changed for a view model type that the current view model is interested in. This can be accomplished by decorating the view model with the InterestedInAttribute.

PrepareForTombstoneState ( object>.IDictionary state ) : void

Prepares the state for tombstoning. This method will be called when the TombstoningMode is set to TombstoningMode.Manual.

RaisePropertyChanged ( object sender, AdvancedPropertyChangedEventArgs e ) : void

Raises the ObservableObject.PropertyChanged event. This is the one and only method that actually raises the ObservableObject.PropertyChanged event. All other methods are (and should be) just overloads that eventually call this method.

RecoverFromTombstoneState ( object>.IDictionary state ) : void

Recovers the state from tombstoning. This method will be called when the TombstoningMode is set to TombstoningMode.Manual.

RegisterViewModelServices ( IServiceLocator serviceLocator ) : void

Registers the default view model services.

ResetModel ( string modelProperty, ModelCleanUpMode modelCleanUpMode ) : void

Resets the model by calling uninitializing and initializing the model again. This means that if the model supports IEditableObject, it will be reset.

SaveAsync ( ) : Task

Saves the data.

UninitializeModel ( string modelProperty, object model, ModelCleanUpMode modelCleanUpMode ) : void

Called when a model uninitialized.

UpdateExplicitViewModelToModelMappings ( ) : void

Updates the view model to model mappings that are defined as ViewModelToModelMode.Explicit.

ViewModelBase ( IServiceLocator serviceLocator, bool supportIEditableObject = true, bool ignoreMultipleModelsWarning = false, bool skipViewModelAttributesInitialization = false ) : System

Initializes a new instance of the ViewModelBase class. This constructor allows the injection of a custom IServiceLocator.

ViewModelBase ( bool supportIEditableObject, bool ignoreMultipleModelsWarning = false, bool skipViewModelAttributesInitialization = false ) : System

Initializes a new instance of the ViewModelBase class.

비공개 메소드들

메소드 설명
Cancel ( ) : Task
CancelAndCloseViewModel ( ) : Task
CancelViewModel ( ) : Task
Close ( ) : Task
CloseViewModel ( bool result ) : Task
DeserializeFromTombstoning ( byte data ) : void

Deserializes the data from a previously stored tombstoning state.

INotifyableViewModel ( IViewModel viewModel, ICatelCommand command, object commandParameter ) : void

Called when a command for a view model type that the current view model is interested in has been executed. This can be accomplished by decorating the view model with the InterestedInAttribute.

This method should only be called by Catel so the ManagedViewModel can invoke it. This method is only used as a pass-through to the actual OnViewModelCommandExecuted method.

INotifyableViewModel ( IViewModel viewModel, ViewModelEvent viewModelEvent, EventArgs e ) : void

Views the model event.

This method should only be called by Catel so the ManagedViewModel can invoke it. This method is only used as a pass-through to the actual OnViewModelEvent method.

INotifyableViewModel ( IViewModel viewModel, string propertyName ) : void

Called when a property has changed for a view model type that the current view model is interested in. This can be accomplished by decorating the view model with the InterestedInAttribute.

This method should only be called by Catel so the ManagedViewModel can invoke it. This method is only used as a pass-through to the actual OnViewModelPropertyChanged method.

IRelationalViewModel ( IViewModel parentViewModel ) : void

Sets the new parent view model of this view model.

Initialize ( ) : Task
InitializeModelInternal ( string modelProperty, object model ) : void

Initializes a model by subscribing to all events.

InitializePropertiesWithAttributes ( ) : void

Initializes the properties with attributes.

InitializeThrottling ( ) : void
InitializeViewModel ( ) : Task
InitializeViewModelMetaData ( Type viewModelType ) : Catel.MVVM.ViewModelMetadata

Initializes the view model meta data. This method only initializes the meta data once per view model type. If a type is already initialized, this method will immediately return.

OnChildViewModelClosed ( object sender, EventArgs e ) : void

Called when the child view model is closed.

OnChildViewModelPropertyChanged ( object sender, PropertyChangedEventArgs e ) : void

Called when a property has changed on the child view model.

OnClosed ( bool result ) : void
OnClosing ( ) : void
OnModelErrorInfoUpdated ( object sender, EventArgs e ) : void

Called when the ModelErrorInfo.Updated event occurs.

OnModelPropertyChangedInternal ( object sender, PropertyChangedEventArgs e ) : void

Handles the PropertyChanged event of a Model.

OnThrottlingTimerTick ( ) : void

Called when the throttling timer ticks.

PrepareForTombstoneStateInternal ( object>.IDictionary state ) : void

Prepares the state for tombstoning.

This method is implemented so the PhoneApplicationPage can call this method.

RecoverFromTombstoneStateInternal ( object>.IDictionary state ) : void

Recovers the state from tombstoning.

This method is implemented so the PhoneApplicationPage can call this method.

Save ( ) : Task
SaveAndCloseViewModel ( ) : Task
SaveViewModel ( ) : Task
SerializeForTombstoning ( ) : byte[]

Serializes the data in the view model for tombstoning.

UninitializeModelInternal ( string modelProperty, object model, ModelCleanUpMode modelCleanUpMode ) : void

Uninitializes a model by unsubscribing from all events.

UninitializeThrottling ( ) : void
ValidateViewModelToModelMappings ( ) : void

Validates the view model to model mappings.

ViewModelBase ( ) : System

Initializes static members of the ViewModelBase class.

메소드 상세

CancelAsync() 보호된 메소드

Cancels the editing of the data.
protected CancelAsync ( ) : Task
리턴 Task

CancelViewModelAsync() 공개 메소드

Cancels the editing of the data.
public CancelViewModelAsync ( ) : Task
리턴 Task

CloseAsync() 보호된 메소드

Closes this instance. Always called after the Cancel of Save method.
protected CloseAsync ( ) : Task
리턴 Task

CloseViewModelAsync() 공개 메소드

Closes this instance. Always called after the Cancel of Save method.
public CloseViewModelAsync ( bool result ) : Task
result bool The result to pass to the view. This will, for example, be used as DialogResult.
리턴 Task

GetAllModels() 보호된 메소드

Gets all models that are decorated with the ModelAttribute.
protected GetAllModels ( ) : object[]
리턴 object[]

GetChildViewModels() 보호된 메소드

Gets the child view models of this view model.
protected GetChildViewModels ( ) : IEnumerable
리턴 IEnumerable

InitializeAsync() 보호된 메소드

Initializes the view model. Normally the initialization is done in the constructor, but sometimes this must be delayed to a state where the associated UI element (user control, window, ...) is actually loaded. This method is called as soon as the associated UI element is loaded.
It's not recommended to implement the initialization of properties in this method. The initialization of properties should be done in the constructor. This method should be used to start the retrieval of data from a web service or something similar. During unit tests, it is recommended to manually call this method because there is no external container calling this method.
protected InitializeAsync ( ) : Task
리턴 Task

InitializeModel() 보호된 메소드

Called when a model initialized.
protected InitializeModel ( string modelProperty, object model ) : void
modelProperty string The name of the model property.
model object The model.
리턴 void

InitializeViewModelAsync() 공개 메소드

Initializes the view model. Normally the initialization is done in the constructor, but sometimes this must be delayed to a state where the associated UI element (user control, window, ...) is actually loaded. This method is called as soon as the associated UI element is loaded.
It's not recommended to implement the initialization of properties in this method. The initialization of properties should be done in the constructor. This method should be used to start the retrieval of data from a web service or something similar. During unit tests, it is recommended to manually call this method because there is no external container calling this method.
public InitializeViewModelAsync ( ) : Task
리턴 Task

InitializeViewModelAttributes() 보호된 메소드

Initializes the view model attributes, such as the ModelAttribute and ViewModelToModelAttribute. This method is automatically invoked by the constructor. Sometimes, dynamic properties are registered after the constructor. Therefore, it is possible to skip the initialization of the attributes and handle this manually.
A mapped model is not registered. A mapped model property is not found.
protected InitializeViewModelAttributes ( ) : void
리턴 void

IsModelRegistered() 보호된 메소드

Determines whether a specific property is registered as a model.
protected IsModelRegistered ( string name ) : bool
name string The name of the registered model.
리턴 bool

OnClosedAsync() 보호된 메소드

Called when the view model has just been closed. This method also raises the Closed event.
protected OnClosedAsync ( bool result ) : Task
result bool The result to pass to the view. This will, for example, be used as DialogResult.
리턴 Task

OnClosingAsync() 보호된 메소드

Called when the view model is about to be closed. This method also raises the Closing event.
protected OnClosingAsync ( ) : Task
리턴 Task

OnModelPropertyChanged() 보호된 메소드

Called when a property on one of the registered models has changed.
This method will also raise for properties that are not mapped on the view model.
protected OnModelPropertyChanged ( object sender, PropertyChangedEventArgs e ) : void
sender object The sender.
e System.ComponentModel.PropertyChangedEventArgs The instance containing the event data.
리턴 void

OnPropertyChanged() 보호된 메소드

Called when a property value has changed.
protected OnPropertyChanged ( AdvancedPropertyChangedEventArgs e ) : void
e AdvancedPropertyChangedEventArgs The instance containing the event data.
리턴 void

OnValidated() 보호된 메소드

Called when the object is validated.
protected OnValidated ( IValidationContext validationContext ) : void
validationContext IValidationContext The validation context.
리턴 void

OnValidating() 보호된 메소드

Called when the object is validating.
protected OnValidating ( IValidationContext validationContext ) : void
validationContext IValidationContext The validation context.
리턴 void

OnValidatingBusinessRules() 보호된 메소드

Called when the object is validating the business rules.
protected OnValidatingBusinessRules ( IValidationContext validationContext ) : void
validationContext IValidationContext The validation context.
리턴 void

OnValidatingFields() 보호된 메소드

Called when the object is validating the fields.
protected OnValidatingFields ( IValidationContext validationContext ) : void
validationContext IValidationContext The validation context.
리턴 void

OnViewModelCommandExecuted() 보호된 메소드

Called when a command for a view model type that the current view model is interested in has been executed. This can be accomplished by decorating the view model with the InterestedInAttribute.
protected OnViewModelCommandExecuted ( IViewModel viewModel, ICatelCommand command, object commandParameter ) : void
viewModel IViewModel The view model.
command ICatelCommand The command that has been executed.
commandParameter object The command parameter used during the execution.
리턴 void

OnViewModelEvent() 보호된 메소드

Called when an event for a view model type that the current view model is interested in has been raised. This can be accomplished by decorating the view model with the InterestedInAttribute.
protected OnViewModelEvent ( IViewModel viewModel, ViewModelEvent viewModelEvent, EventArgs e ) : void
viewModel IViewModel The view model.
viewModelEvent ViewModelEvent The view model event.
e System.EventArgs The instance containing the event data.
리턴 void

OnViewModelPropertyChanged() 보호된 메소드

Called when a property has changed for a view model type that the current view model is interested in. This can be accomplished by decorating the view model with the InterestedInAttribute.
protected OnViewModelPropertyChanged ( IViewModel viewModel, string propertyName ) : void
viewModel IViewModel The view model.
propertyName string Name of the property.
리턴 void

PrepareForTombstoneState() 보호된 메소드

Prepares the state for tombstoning. This method will be called when the TombstoningMode is set to TombstoningMode.Manual.
protected PrepareForTombstoneState ( object>.IDictionary state ) : void
state object>.IDictionary The target state which can be used to store values.
리턴 void

RaisePropertyChanged() 보호된 메소드

Raises the ObservableObject.PropertyChanged event. This is the one and only method that actually raises the ObservableObject.PropertyChanged event. All other methods are (and should be) just overloads that eventually call this method.
protected RaisePropertyChanged ( object sender, AdvancedPropertyChangedEventArgs e ) : void
sender object The sender.
e AdvancedPropertyChangedEventArgs The instance containing the event data.
리턴 void

RecoverFromTombstoneState() 보호된 메소드

Recovers the state from tombstoning. This method will be called when the TombstoningMode is set to TombstoningMode.Manual.
protected RecoverFromTombstoneState ( object>.IDictionary state ) : void
state object>.IDictionary The source state to recover values from.
리턴 void

RegisterViewModelServices() 보호된 메소드

Registers the default view model services.
The is null.
protected RegisterViewModelServices ( IServiceLocator serviceLocator ) : void
serviceLocator IServiceLocator The service locator.
리턴 void

ResetModel() 보호된 메소드

Resets the model by calling uninitializing and initializing the model again. This means that if the model supports IEditableObject, it will be reset.
The is null.
protected ResetModel ( string modelProperty, ModelCleanUpMode modelCleanUpMode ) : void
modelProperty string The model property.
modelCleanUpMode ModelCleanUpMode The model clean up mode.
리턴 void

SaveAsync() 보호된 메소드

Saves the data.
protected SaveAsync ( ) : Task
리턴 Task

SaveViewModelAsync() 공개 메소드

Saves the data.
public SaveViewModelAsync ( ) : Task
리턴 Task

ToString() 공개 메소드

Converts the object to a string.
public ToString ( ) : string
리턴 string

UninitializeModel() 보호된 메소드

Called when a model uninitialized.
protected UninitializeModel ( string modelProperty, object model, ModelCleanUpMode modelCleanUpMode ) : void
modelProperty string The name of the model property.
model object The model.
modelCleanUpMode ModelCleanUpMode The model clean up mode.
리턴 void

UpdateExplicitViewModelToModelMappings() 보호된 메소드

Updates the view model to model mappings that are defined as ViewModelToModelMode.Explicit.
protected UpdateExplicitViewModelToModelMappings ( ) : void
리턴 void

ValidateViewModel() 공개 메소드

Validates the specified notify changed properties only.
This method is useful when the view model is initialized before the window, and therefore WPF does not update the errors and warnings.
public ValidateViewModel ( bool force = false, bool notifyChangedPropertiesOnly = true ) : bool
force bool If set to true, a validation is forced (even if the object knows it is already validated).
notifyChangedPropertiesOnly bool if set to true only the properties for which the warnings or errors have been changed /// will be updated via ; otherwise all the properties that /// had warnings or errors but not anymore and properties still containing warnings or errors will be updated.
리턴 bool

ViewModelBase() 보호된 메소드

Initializes a new instance of the ViewModelBase class. This constructor allows the injection of a custom IServiceLocator.
A mapped model is not registered. A mapped model property is not found.
protected ViewModelBase ( IServiceLocator serviceLocator, bool supportIEditableObject = true, bool ignoreMultipleModelsWarning = false, bool skipViewModelAttributesInitialization = false ) : System
serviceLocator IServiceLocator The service locator to inject. If null, the will be used.
supportIEditableObject bool if set to true, the view model will natively support models that /// implement the interface.
ignoreMultipleModelsWarning bool if set to true, the warning when using multiple models is ignored.
skipViewModelAttributesInitialization bool if set to true, the initialization will be skipped and must be done manually via .
리턴 System

ViewModelBase() 보호된 메소드

Initializes a new instance of the ViewModelBase class.
A mapped model is not registered. A mapped model property is not found.
protected ViewModelBase ( bool supportIEditableObject, bool ignoreMultipleModelsWarning = false, bool skipViewModelAttributesInitialization = false ) : System
supportIEditableObject bool if set to true, the view model will natively support models that /// implement the interface.
ignoreMultipleModelsWarning bool if set to true, the warning when using multiple models is ignored.
skipViewModelAttributesInitialization bool /// if set to true, the initialization will be skipped and must be done manually via . ///
리턴 System