CSLA.NET 5.4.2
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
Csla.Xaml.ViewModelBase< T > Class Template Reference

Base class used to create ViewModel objects that implement their own commands/verbs/actions. More...

Inheritance diagram for Csla.Xaml.ViewModelBase< T >:
Csla.Xaml.IViewModel Csla.Xaml.ViewModel< T > Csla.Xaml.CancellableViewModel< T >

Public Member Functions

async Task< ViewModelBase< T > > InitAsync ()
 Method used to perform async initialization of the viewmodel. More...
 

Static Public Attributes

static readonly DependencyProperty ModelProperty
 Gets or sets the Model object. More...
 
static readonly DependencyProperty ManageObjectLifetimeProperty
 Gets or sets a value indicating whether the ViewModel should automatically managed the lifetime of the Model. More...
 

Protected Member Functions

 ViewModelBase ()
 Create new instance of base class used to create ViewModel objects that implement their own commands/verbs/actions. More...
 
virtual async Task< T > DoInitAsync ()
 Override this method to implement async initialization of the model object. More...
 
virtual void OnError (Exception error)
 Raises ErrorOccurred event when an error occurs during processing. More...
 
virtual void DoRefresh (Func< T > factoryMethod)
 Creates or retrieves a new instance of the Model by invoking a static factory method. More...
 
virtual void DoRefresh (string factoryMethod, params object[] factoryParameters)
 Creates or retrieves a new instance of the Model by invoking a static factory method. More...
 
virtual void DoRefresh (string factoryMethod)
 Creates or retrieves a new instance of the Model by invoking a static factory method. More...
 
virtual void BeginRefresh (Action< EventHandler< DataPortalResult< T > > > factoryMethod)
 Creates or retrieves a new instance of the Model by invoking a static factory method. More...
 
virtual void BeginRefresh (string factoryMethod, params object[] factoryParameters)
 Creates or retrieves a new instance of the Model by invoking a static factory method. More...
 
virtual void BeginRefresh (string factoryMethod)
 Creates or retrieves a new instance of the Model by invoking a static factory method. More...
 
virtual void OnRefreshing (T model)
 Method called after a refresh operation has completed and before the model is updated. More...
 
virtual void OnRefreshed ()
 Method called after a refresh operation has completed. More...
 
virtual T DoSave ()
 Saves the Model, first committing changes if ManagedObjectLifetime is true. More...
 
virtual void BeginSave ()
 Saves the Model, first committing changes if ManagedObjectLifetime is true. More...
 
virtual void OnSaving (T model)
 Method called after a save operation has completed and before Model is updated (when successful). More...
 
virtual void OnSaved ()
 Method called after a save operation has completed (whether successful or not). More...
 
virtual async Task< T > RefreshAsync< F > (Func< Task< T > > factory)
 Creates or retrieves a new instance of the Model by invoking an action. More...
 
virtual async Task< T > SaveAsync ()
 Saves the Model, first committing changes if ManagedObjectLifetime is true. More...
 
virtual void DoCancel ()
 Cancels changes made to the model if ManagedObjectLifetime is true. More...
 
virtual object DoAddNew ()
 Adds a new item to the Model (if it is a collection). More...
 
virtual void DoRemove (object item)
 Removes an item from the Model (if it is a collection). More...
 
virtual void DoDelete ()
 Marks the Model for deletion (if it is an editable root object). More...
 
virtual void OnModelChanged (T oldValue, T newValue)
 Invoked when the Model changes, allowing event handlers to be unhooked from the old object and hooked on the new object. More...
 
void UnhookChangedEvents (T model)
 Unhooks changed event handlers from the model. More...
 
virtual void OnSetProperties ()
 Override this method to hook into to logic of setting properties when model is changed or edited. More...
 
virtual void OnPropertyChanged (string propertyName)
 Raise the PropertyChanged event. More...
 

Properties

Exception Error [getprotected set]
 Gets the Error object corresponding to the last asynchronous operation. More...
 
Model [getset]
 Gets or sets the Model object. More...
 
bool ManageObjectLifetime [getset]
 Gets or sets a value indicating whether the ViewManageObjectLifetime should automatically managed the lifetime of the ManageObjectLifetime. More...
 
bool IsBusy [getprotected set]
 Gets a value indicating whether this object is executing an asynchronous process. More...
 
virtual bool IsDirty [getprotected set]
 Gets a value indicating whether the Model has been changed. More...
 
virtual bool IsValid [getprotected set]
 Gets a value indicating whether the Model is currently valid (has no broken rules). More...
 
virtual bool CanSave [getprotected set]
 Gets a value indicating whether the Model can currently be saved. More...
 
virtual bool CanCancel [getprotected set]
 Gets a value indicating whether the Model can currently be canceled. More...
 
virtual bool CanCreate [getprotected set]
 Gets a value indicating whether an instance of the Model can currently be created. More...
 
virtual bool CanDelete [getprotected set]
 Gets a value indicating whether the Model can currently be deleted. More...
 
virtual bool CanFetch [getprotected set]
 Gets a value indicating whether an instance of the Model can currently be retrieved. More...
 
virtual bool CanRemove [getprotected set]
 Gets a value indicating whether the Model can currently be removed. More...
 
virtual bool CanAddNew [getprotected set]
 Gets a value indicating whether the Model can currently be added. More...
 
virtual bool CanCreateObject [getprotected set]
 Gets a value indicating whether the current user is authorized to create a Model. More...
 
virtual bool CanGetObject [getprotected set]
 Gets a value indicating whether the current user is authorized to retrieve a Model. More...
 
virtual bool CanEditObject [getprotected set]
 Gets a value indicating whether the current user is authorized to save (insert or update a Model. More...
 
virtual bool CanDeleteObject [getprotected set]
 Gets a value indicating whether the current user is authorized to delete a Model. More...
 
- Properties inherited from Csla.Xaml.IViewModel
object Model [getset]
 Gets or sets the Model property of the viewmodel object. More...
 

Events

EventHandler< ErrorEventArgsErrorOccurred
 Event raised when an error occurs during processing. More...
 
PropertyChangedEventHandler PropertyChanged
 Event raised when a property changes. More...
 

Detailed Description

Base class used to create ViewModel objects that implement their own commands/verbs/actions.

Template Parameters
TType of the Model object.

Definition at line 40 of file Csla.Xaml.Shared/ViewModelBase.cs.

Constructor & Destructor Documentation

◆ ViewModelBase()

Create new instance of base class used to create ViewModel objects that implement their own commands/verbs/actions.

Definition at line 48 of file Csla.Xaml.Shared/ViewModelBase.cs.

Member Function Documentation

◆ BeginRefresh() [1/3]

virtual void Csla.Xaml.ViewModelBase< T >.BeginRefresh ( Action< EventHandler< DataPortalResult< T > > >  factoryMethod)
protectedvirtual

Creates or retrieves a new instance of the Model by invoking a static factory method.

Parameters
factoryMethodStatic factory method action.

BeginRefresh(BusinessList.BeginGetList)

BeginRefresh(handler => BusinessList.BeginGetList(handler))

BeginRefresh(handler => BusinessList.BeginGetList(id, handler))

Reimplemented in Csla.Xaml.CancellableViewModel< T >.

Definition at line 218 of file Csla.Xaml.Shared/ViewModelBase.cs.

◆ BeginRefresh() [2/3]

virtual void Csla.Xaml.ViewModelBase< T >.BeginRefresh ( string  factoryMethod)
protectedvirtual

Creates or retrieves a new instance of the Model by invoking a static factory method.

Parameters
factoryMethodName of the static factory method.

Definition at line 274 of file Csla.Xaml.Shared/ViewModelBase.cs.

◆ BeginRefresh() [3/3]

virtual void Csla.Xaml.ViewModelBase< T >.BeginRefresh ( string  factoryMethod,
params object[]  factoryParameters 
)
protectedvirtual

Creates or retrieves a new instance of the Model by invoking a static factory method.

Parameters
factoryMethodName of the static factory method.
factoryParametersFactory method parameters.

Reimplemented in Csla.Xaml.CancellableViewModel< T >.

Definition at line 245 of file Csla.Xaml.Shared/ViewModelBase.cs.

◆ BeginSave()

virtual void Csla.Xaml.ViewModelBase< T >.BeginSave ( )
protectedvirtual

Saves the Model, first committing changes if ManagedObjectLifetime is true.

Definition at line 371 of file Csla.Xaml.Shared/ViewModelBase.cs.

◆ DoAddNew()

virtual object Csla.Xaml.ViewModelBase< T >.DoAddNew ( )
protectedvirtual

Adds a new item to the Model (if it is a collection).

Definition at line 1005 of file Csla.Xaml.Shared/ViewModelBase.cs.

◆ DoCancel()

virtual void Csla.Xaml.ViewModelBase< T >.DoCancel ( )
protectedvirtual

Cancels changes made to the model if ManagedObjectLifetime is true.

Definition at line 955 of file Csla.Xaml.Shared/ViewModelBase.cs.

◆ DoDelete()

virtual void Csla.Xaml.ViewModelBase< T >.DoDelete ( )
protectedvirtual

Marks the Model for deletion (if it is an editable root object).

Definition at line 1038 of file Csla.Xaml.Shared/ViewModelBase.cs.

◆ DoInitAsync()

virtual async Task< T > Csla.Xaml.ViewModelBase< T >.DoInitAsync ( )
protectedvirtual

Override this method to implement async initialization of the model object.

The result of this method is used to set the Model property of the viewmodel.

Returns
A Task that creates the model object.

Definition at line 88 of file Csla.Xaml.Shared/ViewModelBase.cs.

◆ DoRefresh() [1/3]

virtual void Csla.Xaml.ViewModelBase< T >.DoRefresh ( Func< T >  factoryMethod)
protectedvirtual

Creates or retrieves a new instance of the Model by invoking a static factory method.

Parameters
factoryMethodStatic factory method function.

DoRefresh(BusinessList.GetList)

DoRefresh(() => BusinessList.GetList())

DoRefresh(() => BusinessList.GetList(id))

Definition at line 150 of file Csla.Xaml.Shared/ViewModelBase.cs.

◆ DoRefresh() [2/3]

virtual void Csla.Xaml.ViewModelBase< T >.DoRefresh ( string  factoryMethod)
protectedvirtual

Creates or retrieves a new instance of the Model by invoking a static factory method.

Parameters
factoryMethodName of the static factory method.

Definition at line 203 of file Csla.Xaml.Shared/ViewModelBase.cs.

◆ DoRefresh() [3/3]

virtual void Csla.Xaml.ViewModelBase< T >.DoRefresh ( string  factoryMethod,
params object[]  factoryParameters 
)
protectedvirtual

Creates or retrieves a new instance of the Model by invoking a static factory method.

Parameters
factoryMethodName of the static factory method.
factoryParametersFactory method parameters.

Definition at line 177 of file Csla.Xaml.Shared/ViewModelBase.cs.

◆ DoRemove()

virtual void Csla.Xaml.ViewModelBase< T >.DoRemove ( object  item)
protectedvirtual

Removes an item from the Model (if it is a collection).

Definition at line 1028 of file Csla.Xaml.Shared/ViewModelBase.cs.

◆ DoSave()

virtual T Csla.Xaml.ViewModelBase< T >.DoSave ( )
protectedvirtual

Saves the Model, first committing changes if ManagedObjectLifetime is true.

Definition at line 333 of file Csla.Xaml.Shared/ViewModelBase.cs.

◆ InitAsync()

async Task< ViewModelBase< T > > Csla.Xaml.ViewModelBase< T >.InitAsync ( )

Method used to perform async initialization of the viewmodel.

This method is usually invoked immediately following construction of the object instance.

Returns

Definition at line 62 of file Csla.Xaml.Shared/ViewModelBase.cs.

◆ OnError()

virtual void Csla.Xaml.ViewModelBase< T >.OnError ( Exception  error)
protectedvirtual

Raises ErrorOccurred event when an error occurs during processing.

Parameters
error

Definition at line 131 of file Csla.Xaml.Shared/ViewModelBase.cs.

◆ OnModelChanged()

virtual void Csla.Xaml.ViewModelBase< T >.OnModelChanged ( oldValue,
newValue 
)
protectedvirtual

Invoked when the Model changes, allowing event handlers to be unhooked from the old object and hooked on the new object.

Parameters
oldValuePrevious Model reference.
newValueNew Model reference.

Definition at line 1050 of file Csla.Xaml.Shared/ViewModelBase.cs.

◆ OnPropertyChanged()

virtual void Csla.Xaml.ViewModelBase< T >.OnPropertyChanged ( string  propertyName)
protectedvirtual

Raise the PropertyChanged event.

Parameters
propertyNameName of the changed property.

Definition at line 1159 of file Csla.Xaml.Shared/ViewModelBase.cs.

◆ OnRefreshed()

virtual void Csla.Xaml.ViewModelBase< T >.OnRefreshed ( )
protectedvirtual

Method called after a refresh operation has completed.

Definition at line 325 of file Csla.Xaml.Shared/ViewModelBase.cs.

◆ OnRefreshing()

virtual void Csla.Xaml.ViewModelBase< T >.OnRefreshing ( model)
protectedvirtual

Method called after a refresh operation has completed and before the model is updated.

Parameters
modelThe model.

Definition at line 317 of file Csla.Xaml.Shared/ViewModelBase.cs.

◆ OnSaved()

virtual void Csla.Xaml.ViewModelBase< T >.OnSaved ( )
protectedvirtual

Method called after a save operation has completed (whether successful or not).

Definition at line 432 of file Csla.Xaml.Shared/ViewModelBase.cs.

◆ OnSaving()

virtual void Csla.Xaml.ViewModelBase< T >.OnSaving ( model)
protectedvirtual

Method called after a save operation has completed and before Model is updated (when successful).

Definition at line 423 of file Csla.Xaml.Shared/ViewModelBase.cs.

◆ OnSetProperties()

virtual void Csla.Xaml.ViewModelBase< T >.OnSetProperties ( )
protectedvirtual

Override this method to hook into to logic of setting properties when model is changed or edited.

Definition at line 1114 of file Csla.Xaml.Shared/ViewModelBase.cs.

◆ RefreshAsync< F >()

virtual async Task< T > Csla.Xaml.ViewModelBase< T >.RefreshAsync< F > ( Func< Task< T > >  factory)
protectedvirtual

Creates or retrieves a new instance of the Model by invoking an action.

Parameters
factoryFactory method to invoke

Definition at line 903 of file Csla.Xaml.Shared/ViewModelBase.cs.

◆ SaveAsync()

virtual async Task< T > Csla.Xaml.ViewModelBase< T >.SaveAsync ( )
protectedvirtual

Saves the Model, first committing changes if ManagedObjectLifetime is true.

Definition at line 923 of file Csla.Xaml.Shared/ViewModelBase.cs.

◆ UnhookChangedEvents()

void Csla.Xaml.ViewModelBase< T >.UnhookChangedEvents ( model)
protected

Unhooks changed event handlers from the model.

Parameters
model

Definition at line 1082 of file Csla.Xaml.Shared/ViewModelBase.cs.

Member Data Documentation

◆ ManageObjectLifetimeProperty

readonly DependencyProperty Csla.Xaml.ViewModelBase< T >.ManageObjectLifetimeProperty
static
Initial value:
=
DependencyProperty.Register("ManageObjectLifetime", typeof(bool),
typeof(ViewModelBase<T>), new PropertyMetadata(true))

Gets or sets a value indicating whether the ViewModel should automatically managed the lifetime of the Model.

Definition at line 486 of file Csla.Xaml.Shared/ViewModelBase.cs.

◆ ModelProperty

readonly DependencyProperty Csla.Xaml.ViewModelBase< T >.ModelProperty
static
Initial value:
=
DependencyProperty.Register("Model", typeof(T), typeof(ViewModelBase<T>),
new PropertyMetadata((o, e) =>
{
var viewmodel = (ViewModelBase<T>)o;
viewmodel.OnModelChanged((T)e.OldValue, (T)e.NewValue);
}))

Gets or sets the Model object.

Definition at line 460 of file Csla.Xaml.Shared/ViewModelBase.cs.

Property Documentation

◆ CanAddNew

virtual bool Csla.Xaml.ViewModelBase< T >.CanAddNew
getprotected set

Gets a value indicating whether the Model can currently be added.

Definition at line 713 of file Csla.Xaml.Shared/ViewModelBase.cs.

◆ CanCancel

virtual bool Csla.Xaml.ViewModelBase< T >.CanCancel
getprotected set

Gets a value indicating whether the Model can currently be canceled.

Definition at line 601 of file Csla.Xaml.Shared/ViewModelBase.cs.

◆ CanCreate

virtual bool Csla.Xaml.ViewModelBase< T >.CanCreate
getprotected set

Gets a value indicating whether an instance of the Model can currently be created.

Definition at line 624 of file Csla.Xaml.Shared/ViewModelBase.cs.

◆ CanCreateObject

virtual bool Csla.Xaml.ViewModelBase< T >.CanCreateObject
getprotected set

Gets a value indicating whether the current user is authorized to create a Model.

Definition at line 809 of file Csla.Xaml.Shared/ViewModelBase.cs.

◆ CanDelete

virtual bool Csla.Xaml.ViewModelBase< T >.CanDelete
getprotected set

Gets a value indicating whether the Model can currently be deleted.

Definition at line 646 of file Csla.Xaml.Shared/ViewModelBase.cs.

◆ CanDeleteObject

virtual bool Csla.Xaml.ViewModelBase< T >.CanDeleteObject
getprotected set

Gets a value indicating whether the current user is authorized to delete a Model.

Definition at line 868 of file Csla.Xaml.Shared/ViewModelBase.cs.

◆ CanEditObject

virtual bool Csla.Xaml.ViewModelBase< T >.CanEditObject
getprotected set

Gets a value indicating whether the current user is authorized to save (insert or update a Model.

Definition at line 848 of file Csla.Xaml.Shared/ViewModelBase.cs.

◆ CanFetch

virtual bool Csla.Xaml.ViewModelBase< T >.CanFetch
getprotected set

Gets a value indicating whether an instance of the Model can currently be retrieved.

Definition at line 669 of file Csla.Xaml.Shared/ViewModelBase.cs.

◆ CanGetObject

virtual bool Csla.Xaml.ViewModelBase< T >.CanGetObject
getprotected set

Gets a value indicating whether the current user is authorized to retrieve a Model.

Definition at line 828 of file Csla.Xaml.Shared/ViewModelBase.cs.

◆ CanRemove

virtual bool Csla.Xaml.ViewModelBase< T >.CanRemove
getprotected set

Gets a value indicating whether the Model can currently be removed.

Definition at line 691 of file Csla.Xaml.Shared/ViewModelBase.cs.

◆ CanSave

virtual bool Csla.Xaml.ViewModelBase< T >.CanSave
getprotected set

Gets a value indicating whether the Model can currently be saved.

Definition at line 579 of file Csla.Xaml.Shared/ViewModelBase.cs.

◆ Error

Exception Csla.Xaml.ViewModelBase< T >.Error
getprotected set

Gets the Error object corresponding to the last asynchronous operation.

Definition at line 104 of file Csla.Xaml.Shared/ViewModelBase.cs.

◆ IsBusy

bool Csla.Xaml.ViewModelBase< T >.IsBusy
getprotected set

Gets a value indicating whether this object is executing an asynchronous process.

Definition at line 515 of file Csla.Xaml.Shared/ViewModelBase.cs.

◆ IsDirty

virtual bool Csla.Xaml.ViewModelBase< T >.IsDirty
getprotected set

Gets a value indicating whether the Model has been changed.

Definition at line 535 of file Csla.Xaml.Shared/ViewModelBase.cs.

◆ IsValid

virtual bool Csla.Xaml.ViewModelBase< T >.IsValid
getprotected set

Gets a value indicating whether the Model is currently valid (has no broken rules).

Definition at line 557 of file Csla.Xaml.Shared/ViewModelBase.cs.

◆ ManageObjectLifetime

bool Csla.Xaml.ViewModelBase< T >.ManageObjectLifetime
getset

Gets or sets a value indicating whether the ViewManageObjectLifetime should automatically managed the lifetime of the ManageObjectLifetime.

Definition at line 498 of file Csla.Xaml.Shared/ViewModelBase.cs.

◆ Model

T Csla.Xaml.ViewModelBase< T >.Model
getset

Gets or sets the Model object.

Definition at line 471 of file Csla.Xaml.Shared/ViewModelBase.cs.

Event Documentation

◆ ErrorOccurred

EventHandler<ErrorEventArgs> Csla.Xaml.ViewModelBase< T >.ErrorOccurred

Event raised when an error occurs during processing.

Definition at line 123 of file Csla.Xaml.Shared/ViewModelBase.cs.

◆ PropertyChanged

PropertyChangedEventHandler Csla.Xaml.ViewModelBase< T >.PropertyChanged

Event raised when a property changes.

Definition at line 1153 of file Csla.Xaml.Shared/ViewModelBase.cs.