Class ViewModel
- Namespace
- CarinaStudio.ViewModels
- Assembly
- CarinaStudio.AppBase.Application.dll
Base class for view-model.
public abstract class ViewModel : BaseDisposable, IDisposable, IApplicationObject, IThreadDependent, ISynchronizable, INotifyPropertyChanged
- Inheritance
-
ViewModel
- Implements
- Derived
- Inherited Members
- Extension Methods
Constructors
ViewModel(IApplication)
Initialize new ViewModel instance.
protected ViewModel(IApplication app)
Parameters
appIApplicationIApplication which view-model belongs to.
Fields
HasNecessaryTasksProperty
Property of HasNecessaryTasks.
public static readonly ObservableProperty<bool> HasNecessaryTasksProperty
Field Value
OwnerProperty
Property of Owner.
public static readonly ObservableProperty<ViewModel?> OwnerProperty
Field Value
Properties
Application
Get IApplication which view-model belongs to.
public IApplication Application { get; }
Property Value
HasNecessaryTasks
Check whether at least one necessary task is not completed yet or not.
public bool HasNecessaryTasks { get; }
Property Value
Id
Get unique ID of view-model instance.
public int Id { get; }
Property Value
Logger
Logger of this instance.
protected ILogger Logger { get; }
Property Value
OwnedViewModels
Get list of ViewModel which is owned by this instance.
protected IList<ViewModel> OwnedViewModels { get; }
Property Value
Owner
Get or set owner of this view-model.
public ViewModel? Owner { get; set; }
Property Value
PersistentState
Get persistent application state.
protected ISettings PersistentState { get; }
Property Value
Settings
Get application user settings.
protected ISettings Settings { get; }
Property Value
SynchronizationContext
Get SynchronizationContext on thread which view-model depends on.
public SynchronizationContext SynchronizationContext { get; }
Property Value
Methods
AddResource(Action, Action)
Add resource which will be disposed when disposing the view-model.
protected void AddResource(Action setup, Action dispose)
Parameters
AddResource(Func<Task>, Func<Task>)
Add resource which will be disposed when disposing the view-model.
protected void AddResource(Func<Task> setupAsync, Func<Task> disposeAsync)
Parameters
setupAsyncFunc<Task>Asynchronous action to set up resource.
disposeAsyncFunc<Task>Asynchronous action to dispose resource.
AddResource(IAsyncDisposable)
Add resource which will be disposed when disposing the view-model.
protected void AddResource(IAsyncDisposable resource)
Parameters
resourceIAsyncDisposableResource to add.
AddResource(IDisposable)
Add resource which will be disposed when disposing the view-model.
protected void AddResource(IDisposable resource)
Parameters
resourceIDisposableResource to add.
AddResources(params IAsyncDisposable[])
Add resources which will be disposed when disposing the view-model.
protected void AddResources(params IAsyncDisposable[] resources)
Parameters
resourcesIAsyncDisposable[]Resources to add.
AddResources(params IDisposable[])
Add resources which will be disposed when disposing the view-model.
protected void AddResources(params IDisposable[] resources)
Parameters
resourcesIDisposable[]Resources to add.
CheckAccess()
Check whether current thread is the thread which view-model depends on or not.
public bool CheckAccess()
Returns
- bool
True if current thread is the thread which view-model depends on.
CoerceValue<T>(ObservableProperty<T>, T)
Coerce value for given property.
protected T CoerceValue<T>(ObservableProperty<T> property, T value)
Parameters
propertyObservableProperty<T>Property.
valueTValue.
Returns
- T
Coerced value.
Type Parameters
TType of property value.
Dispose(bool)
Dispose the view-model.
protected override void Dispose(bool disposing)
Parameters
disposingboolTrue to release managed resources.
GetValueAsObservable<T>(ObservableProperty<T>)
Get property value as IObservable<T>.
public IObservable<T> GetValueAsObservable<T>(ObservableProperty<T> property)
Parameters
propertyObservableProperty<T>Property to get.
Returns
- IObservable<T>
IObservable<T> represents value of property.
Type Parameters
TType of value.
GetValue<T>(ObservableProperty<T>)
Get property value.
public T GetValue<T>(ObservableProperty<T> property)
Parameters
propertyObservableProperty<T>Property to get.
Returns
- T
Value of property.
Type Parameters
TType of value.
OnApplicationPropertyChanged(PropertyChangedEventArgs)
Called when property of Application has been changed.
protected virtual void OnApplicationPropertyChanged(PropertyChangedEventArgs e)
Parameters
ePropertyChangedEventArgsEvent data.
OnApplicationStringsUpdated()
Called when application string resources updated.
protected virtual void OnApplicationStringsUpdated()
OnOwnedViewModelAdded(ViewModel)
Called when ViewModel which is owned by this instance has been added.
protected virtual void OnOwnedViewModelAdded(ViewModel viewModel)
Parameters
OnOwnedViewModelRemoved(ViewModel)
Called when ViewModel which is owned by this instance has been removed.
protected virtual void OnOwnedViewModelRemoved(ViewModel viewModel)
Parameters
OnOwnerChanged(ViewModel?, ViewModel?)
Called when owner of the view-model has been changed.
protected virtual void OnOwnerChanged(ViewModel? prevOwner, ViewModel? newOwner)
Parameters
OnPropertyChanged(ObservableProperty, object?, object?)
Called when property changed.
protected virtual void OnPropertyChanged(ObservableProperty property, object? oldValue, object? newValue)
Parameters
propertyObservablePropertyChanged property.
oldValueobjectOld value.
newValueobjectNew value.
OnPropertyChanged(string)
Raise PropertyChanged event.
protected virtual void OnPropertyChanged(string propertyName)
Parameters
propertyNamestringName of changed property.
OnSettingChanged(SettingChangedEventArgs)
Called when application setting has been changed.
protected virtual void OnSettingChanged(SettingChangedEventArgs e)
Parameters
eSettingChangedEventArgsEvent data.
OnSettingChanging(SettingChangingEventArgs)
Called when application setting is changing.
protected virtual void OnSettingChanging(SettingChangingEventArgs e)
Parameters
eSettingChangingEventArgsEvent data.
ResetValue<T>(ObservableProperty<T>)
Reset value of given ObservableProperty to its default value.
protected void ResetValue<T>(ObservableProperty<T> property)
Parameters
propertyObservableProperty<T>ObservableProperty to reset.
Type Parameters
TType of value.
SetValue<T>(ObservableProperty<T>, T)
Set property value.
protected void SetValue<T>(ObservableProperty<T> property, T value)
Parameters
propertyObservableProperty<T>Property to set.
valueTValue.
Type Parameters
TType of value.
ToString()
Get readable string represents this view-model.
public override string ToString()
Returns
- string
String represents this view-model.
WaitForNecessaryTaskAsync(Task)
Treat given task as necessary task and wait for completion.
protected Task WaitForNecessaryTaskAsync(Task task)
Parameters
taskTaskTask.
Returns
- Task
Task or waiting.
Remarks
The task will also be waited by WaitForNecessaryTasksAsync() after calling this method.
WaitForNecessaryTasksAsync()
Wait for completion of all necessary asynchronous tasks.
public virtual Task WaitForNecessaryTasksAsync()
Returns
- Task
Task of waiting.
Remarks
Error generated by tasks will be ignored.
Events
PropertyChanged
Raised when property changed.
public event PropertyChangedEventHandler? PropertyChanged