CSLA .NET 10.0.0
A home for your business logic
Loading...
Searching...
No Matches
Csla.Xaml.ViewModelBase< T > Class Template Referenceabstract

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 >

Public Member Functions

virtual async Task< T?> RefreshAsync< F > (Func< Task< T?> > factory)
 Creates or retrieves a new instance of the Model by invoking an action.
virtual async Task< T?> SaveAsync ()
 Saves the Model, first committing changes if ManagedObjectLifetime is true.

Static Public Attributes

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

Protected Member Functions

virtual async Task< T?> DoSaveAsync (ISavable? cloned)
 Override to provide custom Model save behavior.
virtual void DoCancel ()
 Cancels changes made to the model if ManagedObjectLifetime is true.
virtual object DoAddNew ()
 Adds a new item to the Model (if it is a collection).
virtual void DoRemove (object? item)
 Removes an item from the Model (if it is a collection).
virtual void DoDelete ()
 Marks the Model for deletion (if it is an editable root object).
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.
void UnhookChangedEvents (T? model)
 Unhooks changed event handlers from the model.
virtual void OnSetProperties ()
 Override this method to hook into to logic of setting properties when model is changed or edited.
virtual void OnPropertyChanged (string propertyName)
 Raise the PropertyChanged event.

Properties

T? Model [get, set]
 Gets or sets the Model object.
bool ManageObjectLifetime [get, set]
 Gets or sets a value indicating whether the ViewManageObjectLifetime should automatically managed the lifetime of the ManageObjectLifetime.
bool IsBusy [get, protected set]
 Gets a value indicating whether this object is executing an asynchronous process.
virtual bool IsDirty [get, protected set]
 Gets a value indicating whether the Model has been changed.
virtual bool IsValid [get, protected set]
 Gets a value indicating whether the Model is currently valid (has no broken rules).
virtual bool CanSave [get, protected set]
 Gets a value indicating whether the Model can currently be saved.
virtual bool CanCancel [get, protected set]
 Gets a value indicating whether the Model can currently be canceled.
virtual bool CanCreate [get, protected set]
 Gets a value indicating whether an instance of the Model can currently be created.
virtual bool CanDelete [get, protected set]
 Gets a value indicating whether the Model can currently be deleted.
virtual bool CanFetch [get, protected set]
 Gets a value indicating whether an instance of the Model can currently be retrieved.
virtual bool CanRemove [get, protected set]
 Gets a value indicating whether the Model can currently be removed.
virtual bool CanAddNew [get, protected set]
 Gets a value indicating whether the Model can currently be added.
virtual bool CanCreateObject [get, protected set]
 Gets a value indicating whether the current user is authorized to create a Model.
virtual bool CanGetObject [get, protected set]
 Gets a value indicating whether the current user is authorized to retrieve a Model.
virtual bool CanEditObject [get, protected set]
 Gets a value indicating whether the current user is authorized to save (insert or update a Model.
virtual bool CanDeleteObject [get, protected set]
 Gets a value indicating whether the current user is authorized to delete a Model.

Events

PropertyChangedEventHandler? ModelPropertyChanged
 Event raised when a property on the Model changes.
Action< object, ChildChangedEventArgs >? ModelChildChanged
 Event raised when a child of the Model changes.
Action< object, NotifyCollectionChangedEventArgs >? ModelCollectionChanged
 Event raised the Model changes and is a collection.
PropertyChangedEventHandler? PropertyChanged
 Event raised when a property changes.

Detailed Description

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

Template Parameters
TType of the Model object.

Member Function Documentation

◆ DoAddNew()

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

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

◆ DoCancel()

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

Cancels changes made to the model if ManagedObjectLifetime is true.

◆ DoDelete()

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

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

◆ DoRemove()

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

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

◆ DoSaveAsync()

virtual async Task< T?> Csla.Xaml.ViewModelBase< T >.DoSaveAsync ( ISavable? cloned)
inlineprotectedvirtual

Override to provide custom Model save behavior.

◆ OnModelChanged()

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

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.

◆ OnPropertyChanged()

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

Raise the PropertyChanged event.

Parameters
propertyNameName of the changed property.

◆ OnSetProperties()

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

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

◆ RefreshAsync< F >()

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

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

Parameters
factoryFactory method to invoke

◆ SaveAsync()

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

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

◆ UnhookChangedEvents()

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

Unhooks changed event handlers from the model.

Parameters
model

Member Data Documentation

◆ ManageObjectLifetimeProperty

readonly DependencyProperty Csla.Xaml.ViewModelBase< T >.ManageObjectLifetimeProperty
static
Initial value:
=
DependencyProperty.Register(nameof(ManageObjectLifetime), typeof(bool),
typeof(ViewModelBase<T>), new PropertyMetadata(true))
bool ManageObjectLifetime
Gets or sets a value indicating whether the ViewManageObjectLifetime should automatically managed the...
Definition ViewModelBase.cs:106

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

◆ ModelProperty

readonly DependencyProperty Csla.Xaml.ViewModelBase< T >.ModelProperty
static
Initial value:
=
DependencyProperty.Register(nameof(Model), typeof(T), typeof(ViewModelBase<T>),
new PropertyMetadata((o, e) =>
{
var viewmodel = (ViewModelBase<T>)o;
viewmodel.OnModelChanged((T)e.OldValue, (T)e.NewValue);
}))
T? Model
Gets or sets the Model object.
Definition ViewModelBase.cs:80

Gets or sets the Model object.

Property Documentation

◆ CanAddNew

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

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

◆ CanCancel

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

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

◆ CanCreate

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

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

◆ CanCreateObject

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

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

◆ CanDelete

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

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

◆ CanDeleteObject

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

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

◆ 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.

◆ CanFetch

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

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

◆ CanGetObject

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

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

◆ CanRemove

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

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

◆ CanSave

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

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

◆ IsBusy

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

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

◆ IsDirty

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

Gets a value indicating whether the Model has been changed.

◆ IsValid

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

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

◆ 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.

◆ Model

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

Gets or sets the Model object.

Implements Csla.Xaml.IViewModel.

Event Documentation

◆ ModelChildChanged

Action<object, ChildChangedEventArgs>? Csla.Xaml.ViewModelBase< T >.ModelChildChanged

Event raised when a child of the Model changes.

◆ ModelCollectionChanged

Action<object, NotifyCollectionChangedEventArgs>? Csla.Xaml.ViewModelBase< T >.ModelCollectionChanged

Event raised the Model changes and is a collection.

◆ ModelPropertyChanged

PropertyChangedEventHandler? Csla.Xaml.ViewModelBase< T >.ModelPropertyChanged

Event raised when a property on the Model changes.

◆ PropertyChanged

PropertyChangedEventHandler? Csla.Xaml.ViewModelBase< T >.PropertyChanged

Event raised when a property changes.


The documentation for this class was generated from the following file: