Gorgon
Show / Hide Table of Contents

Interface IViewModel

A base view model interface for the gorgon editor.

Inherited Members
INotifyPropertyChanged.PropertyChanged
INotifyPropertyChanging.PropertyChanging
Namespace: Gorgon.Editor.UI
Assembly: Gorgon.Editor.API.dll
Syntax
public interface IViewModel : INotifyPropertyChanged, INotifyPropertyChanging
Remarks

This is the base class for all view models used by the editor and provides the bare minimum in functionality. This object already implements the INotifyPropertyChanged and the INotifyPropertyChanging interfaces to allow communication with a view.

When implementing a view model, the developers should set up their properties like this:

public ReturnType PropertyName
{
    get => _backingStoreValue;
    set
    {
        // Always check to see if the value has changed. This keeps the view model from being too "chatty" with the UI.
        if (_backingStoreValue == value)
        {
            return;
        }
    // Notify that the property is about to change. This allows the view to do any necessary clean up prior to updating the visual side.
    OnPropertyChanging();
    _backingStoreValue = value;
    // Now, notify that the property has changed. The view will intercept the change and update the visual associated with the property.
    OnPropertyChanged();
}

}

This setup notifies the view that the property has been updated, and that any associated visual should probably update as well. This is the most common pattern to use, however there will be times when a property notification is required from a method. If that is the case, the NotifyPropertyChanged(string), and NotifyPropertyChanging(string) methods should be used like this:
// This could be a callback function for an IEditorCommand<T> object.
private void DoCommandAction()
{
    NotifyPropertyChanging(nameof(ReadOnlyValue));
    _readOnlyValue++;
    NotifyPropertyChanged(nameof(ReadOnlyValue));
}

The difference being that for properties, you do not need to specify the name of the property being updated (the compiler figures it out), and in methods you do.

The view model is also equipped with several events that are used to notify the application that a long running operation is executing. Applications can intercept these events and display a progress panel, or "please wait" panel. These should only be used with asynchronous operations as they will not update correctly if everything is running on the same thread.

Methods

| Edit this page View Source

Load()

Function called when the associated view is loaded.

Declaration
void Load()
| Edit this page View Source

NotifyAllPropertiesChanged()

Function to notify that all properties on this type have changed their values.

Declaration
void NotifyAllPropertiesChanged()
| Edit this page View Source

NotifyAllPropertiesChanging()

Function to notify that all properties on this type are changing their values.

Declaration
void NotifyAllPropertiesChanging()
| Edit this page View Source

NotifyPropertyChanged(string)

Function to notify when a property has been changed.

Declaration
void NotifyPropertyChanged(string propertyName)
Parameters
Type Name Description
string propertyName

Name of the property to change.

Remarks

This method used to notify when a property has changed outside of the property setter, or if a property other than the current property has changed inside of a property setter. The user can specify the name of the property manually through the propertyName parameter.

| Edit this page View Source

NotifyPropertyChanging(string)

Function to notify before a property is changed.

Declaration
void NotifyPropertyChanging(string propertyName)
Parameters
Type Name Description
string propertyName

Name of the property to change.

Remarks

This method is used to notify before a property is changed outside of the property setter, or if a property other than the current property is changing inside of a property setter. The user can specify the name of the property manually through the propertyName parameter.

| Edit this page View Source

Unload()

Function called when the associated view is unloaded.

Declaration
void Unload()

Events

| Edit this page View Source

ProgressDeactivated

Event triggered when the progress overlay should be deactivated.

Declaration
event EventHandler ProgressDeactivated
Event Type
Type Description
EventHandler
| Edit this page View Source

ProgressUpdated

Event triggered when the progress overlay panel over needs to be updated.

Declaration
event EventHandler<ProgressPanelUpdateArgs> ProgressUpdated
Event Type
Type Description
EventHandler<ProgressPanelUpdateArgs>
| Edit this page View Source

WaitPanelActivated

Event triggered when a wait overlay panel needs to be activated.

Declaration
event EventHandler<WaitPanelActivateArgs> WaitPanelActivated
Event Type
Type Description
EventHandler<WaitPanelActivateArgs>
| Edit this page View Source

WaitPanelDeactivated

Event triggered when a wait overlay panel needs to be deactivated.

Declaration
event EventHandler WaitPanelDeactivated
Event Type
Type Description
EventHandler

Extension Methods

GorgonDebugExtensions.ValidateObject<T>(T, string)
GorgonNullExtensions.AsNullable<T>(object)
GorgonNullExtensions.IfNull<T>(object, T)
GorgonNullExtensions.IsNull(object)
  • Edit this page
  • View Source
In this article
Back to top Copyright 2023 - Licensed under the MIT license by Michael Winsor (Tape_Worm).
Send comments on this topic to the author