Table of Contents

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

app IApplication

IApplication which view-model belongs to.

Fields

HasNecessaryTasksProperty

Property of HasNecessaryTasks.

public static readonly ObservableProperty<bool> HasNecessaryTasksProperty

Field Value

ObservableProperty<bool>

OwnerProperty

Property of Owner.

public static readonly ObservableProperty<ViewModel?> OwnerProperty

Field Value

ObservableProperty<ViewModel>

Properties

Application

Get IApplication which view-model belongs to.

public IApplication Application { get; }

Property Value

IApplication

HasNecessaryTasks

Check whether at least one necessary task is not completed yet or not.

public bool HasNecessaryTasks { get; }

Property Value

bool

Id

Get unique ID of view-model instance.

public int Id { get; }

Property Value

int

Logger

Logger of this instance.

protected ILogger Logger { get; }

Property Value

ILogger

OwnedViewModels

Get list of ViewModel which is owned by this instance.

protected IList<ViewModel> OwnedViewModels { get; }

Property Value

IList<ViewModel>

Owner

Get or set owner of this view-model.

public ViewModel? Owner { get; set; }

Property Value

ViewModel

PersistentState

Get persistent application state.

protected ISettings PersistentState { get; }

Property Value

ISettings

Settings

Get application user settings.

protected ISettings Settings { get; }

Property Value

ISettings

SynchronizationContext

Get SynchronizationContext on thread which view-model depends on.

public SynchronizationContext SynchronizationContext { get; }

Property Value

SynchronizationContext

Methods

AddResource(Action, Action)

Add resource which will be disposed when disposing the view-model.

protected void AddResource(Action setup, Action dispose)

Parameters

setup Action

Action to set up resource.

dispose Action

Action to dispose resource.

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

setupAsync Func<Task>

Asynchronous action to set up resource.

disposeAsync Func<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

resource IAsyncDisposable

Resource to add.

AddResource(IDisposable)

Add resource which will be disposed when disposing the view-model.

protected void AddResource(IDisposable resource)

Parameters

resource IDisposable

Resource to add.

AddResources(params IAsyncDisposable[])

Add resources which will be disposed when disposing the view-model.

protected void AddResources(params IAsyncDisposable[] resources)

Parameters

resources IAsyncDisposable[]

Resources to add.

AddResources(params IDisposable[])

Add resources which will be disposed when disposing the view-model.

protected void AddResources(params IDisposable[] resources)

Parameters

resources IDisposable[]

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

property ObservableProperty<T>

Property.

value T

Value.

Returns

T

Coerced value.

Type Parameters

T

Type of property value.

Dispose(bool)

Dispose the view-model.

protected override void Dispose(bool disposing)

Parameters

disposing bool

True to release managed resources.

GetValueAsObservable<T>(ObservableProperty<T>)

Get property value as IObservable<T>.

public IObservable<T> GetValueAsObservable<T>(ObservableProperty<T> property)

Parameters

property ObservableProperty<T>

Property to get.

Returns

IObservable<T>

IObservable<T> represents value of property.

Type Parameters

T

Type of value.

GetValue<T>(ObservableProperty<T>)

Get property value.

public T GetValue<T>(ObservableProperty<T> property)

Parameters

property ObservableProperty<T>

Property to get.

Returns

T

Value of property.

Type Parameters

T

Type of value.

OnApplicationPropertyChanged(PropertyChangedEventArgs)

Called when property of Application has been changed.

protected virtual void OnApplicationPropertyChanged(PropertyChangedEventArgs e)

Parameters

e PropertyChangedEventArgs

Event 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

viewModel ViewModel

ViewModel.

OnOwnedViewModelRemoved(ViewModel)

Called when ViewModel which is owned by this instance has been removed.

protected virtual void OnOwnedViewModelRemoved(ViewModel viewModel)

Parameters

viewModel ViewModel

ViewModel.

OnOwnerChanged(ViewModel?, ViewModel?)

Called when owner of the view-model has been changed.

protected virtual void OnOwnerChanged(ViewModel? prevOwner, ViewModel? newOwner)

Parameters

prevOwner ViewModel

Previous owner.

newOwner ViewModel

New owner.

OnPropertyChanged(ObservableProperty, object?, object?)

Called when property changed.

protected virtual void OnPropertyChanged(ObservableProperty property, object? oldValue, object? newValue)

Parameters

property ObservableProperty

Changed property.

oldValue object

Old value.

newValue object

New value.

OnPropertyChanged(string)

Raise PropertyChanged event.

protected virtual void OnPropertyChanged(string propertyName)

Parameters

propertyName string

Name of changed property.

OnSettingChanged(SettingChangedEventArgs)

Called when application setting has been changed.

protected virtual void OnSettingChanged(SettingChangedEventArgs e)

Parameters

e SettingChangedEventArgs

Event data.

OnSettingChanging(SettingChangingEventArgs)

Called when application setting is changing.

protected virtual void OnSettingChanging(SettingChangingEventArgs e)

Parameters

e SettingChangingEventArgs

Event data.

ResetValue<T>(ObservableProperty<T>)

Reset value of given ObservableProperty to its default value.

protected void ResetValue<T>(ObservableProperty<T> property)

Parameters

property ObservableProperty<T>

ObservableProperty to reset.

Type Parameters

T

Type of value.

SetValue<T>(ObservableProperty<T>, T)

Set property value.

protected void SetValue<T>(ObservableProperty<T> property, T value)

Parameters

property ObservableProperty<T>

Property to set.

value T

Value.

Type Parameters

T

Type 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

task Task

Task.

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

Event Type

PropertyChangedEventHandler