Table of Contents

Class ExtendedNotificationObject

Namespace
Acuit.Pinpoint.Windows
Assembly
Acuit.Pinpoint.Windows.dll

This is the abstract base class for any object that provides property change notifications, adding some features beyond the base Prism implementation.

public abstract class ExtendedNotificationObject : NotificationObject, INotifyPropertyChanged
Inheritance
NotificationObject
ExtendedNotificationObject
Implements
Derived
Inherited Members
NotificationObject.PropertyChanged

Methods

AddPropertyChangeWatcher(Action, params string[])

Adds an action that executes when any of the specified properties changes.

public void AddPropertyChangeWatcher(Action action, params string[] propertyNames)

Parameters

action Action

A delegate that performs the action.

propertyNames string[]

The properties to watch for changes. These must be properties on this object.

Examples

This can be used to automatically update a derived property when any of the properties it depends on changes:

class TheViewModel : ExtendedNotificationObject
{
    public TheViewModel()
    {
        AddPropertyChangeWatcher(() =>
        {
            WasScannedOrValid = WasScanned || IsValid;
        }, nameof(WasScanned), nameof(IsValid));
    }

    // Property definitions for WasScanned, IsValid, and WasScannedOrValid...
}

It can also be used to raise CanExecuteChange for a command when properties on which CanExecute depends on change:

private DelegateCommand _addCommand;

public DelegateCommand AddCommand
{
    get
    {
        if (_addCommand is null)
        {
            _addCommand = new DelegateCommand(
                (Action)delegate
                {
                    // Perform the add here...
                },
                // Any changes in properties referenced below must cause RaiseCanExecuteChanged to be called.
                () => IsAddAllowed
                );
            AddPropertyChangeWatcher(() =>
            {
                _addCommand.RaiseCanExecuteChanged();
            }, nameof(IsAddAllowed));
        }
        return _addCommand;
    }
}

Remarks

The action delegate will be called initially and then any time any of the watched properties change.

RaisePropertyChanged(string)

Raises this object's PropertyChanged event.

protected override void RaisePropertyChanged(string propertyName)

Parameters

propertyName string

The property that has a new value.