// --------------------------------------------------------------------------------------------------------------------
//
// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
//
//
// A base class that implements the infrastructure for property change notification and automatically performs UI thread marshalling.
// This class is a modified version of the caliburn micro
//
// --------------------------------------------------------------------------------------------------------------------
namespace HandBrake.ApplicationServices.Utilities
{
using System;
using System.ComponentModel;
using System.Linq.Expressions;
using System.Runtime.Serialization;
///
/// Property Changed Base implimentation.
///
[DataContract]
public class PropertyChangedBase : INotifyPropertyChanged
{
///
/// Creates an instance of .
///
public PropertyChangedBase()
{
IsNotifying = true;
}
///
/// Occurs when a property value changes.
///
public event PropertyChangedEventHandler PropertyChanged = delegate { };
///
/// Enables/Disables property change notification.
///
public bool IsNotifying { get; set; }
///
/// Raises a change notification indicating that all bindings should be refreshed.
///
public virtual void Refresh()
{
NotifyOfPropertyChange(string.Empty);
}
///
/// Notifies subscribers of the property change.
///
/// Name of the property.
public virtual void NotifyOfPropertyChange(string propertyName = null)
{
if (IsNotifying)
{
OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
}
}
///
/// Notifies subscribers of the property change.
///
/// The type of the property.
/// The property expression.
public void NotifyOfPropertyChange(Expression> property)
{
NotifyOfPropertyChange(property.GetMemberInfo().Name);
}
///
/// Raises the event directly.
///
/// The instance containing the event data.
[EditorBrowsable(EditorBrowsableState.Never)]
protected void OnPropertyChanged(PropertyChangedEventArgs e)
{
var handler = PropertyChanged;
if (handler != null)
{
handler(this, e);
}
}
}
}