summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrake.ApplicationServices/Utilities/PropertyChangedBase.cs
diff options
context:
space:
mode:
Diffstat (limited to 'win/CS/HandBrake.ApplicationServices/Utilities/PropertyChangedBase.cs')
-rw-r--r--win/CS/HandBrake.ApplicationServices/Utilities/PropertyChangedBase.cs86
1 files changed, 86 insertions, 0 deletions
diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/PropertyChangedBase.cs b/win/CS/HandBrake.ApplicationServices/Utilities/PropertyChangedBase.cs
new file mode 100644
index 000000000..9809def57
--- /dev/null
+++ b/win/CS/HandBrake.ApplicationServices/Utilities/PropertyChangedBase.cs
@@ -0,0 +1,86 @@
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="PropertyChangedBase.cs" company="HandBrake Project (http://handbrake.fr)">
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+// 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
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrake.ApplicationServices.Utilities
+{
+ using System;
+ using System.ComponentModel;
+ using System.Linq.Expressions;
+ using System.Runtime.Serialization;
+
+ /// <summary>
+ /// Property Changed Base implimentation.
+ /// </summary>
+ [DataContract]
+ public class PropertyChangedBase : INotifyPropertyChanged
+ {
+ /// <summary>
+ /// Creates an instance of <see cref = "PropertyChangedBase" />.
+ /// </summary>
+ public PropertyChangedBase()
+ {
+ IsNotifying = true;
+ }
+
+ /// <summary>
+ /// Occurs when a property value changes.
+ /// </summary>
+ public event PropertyChangedEventHandler PropertyChanged = delegate { };
+
+ /// <summary>
+ /// Enables/Disables property change notification.
+ /// </summary>
+ public bool IsNotifying { get; set; }
+
+ /// <summary>
+ /// Raises a change notification indicating that all bindings should be refreshed.
+ /// </summary>
+ public virtual void Refresh()
+ {
+ NotifyOfPropertyChange(string.Empty);
+ }
+
+ /// <summary>
+ /// Notifies subscribers of the property change.
+ /// </summary>
+ /// <param name = "propertyName">Name of the property.</param>
+ public virtual void NotifyOfPropertyChange(string propertyName = null)
+ {
+ if (IsNotifying)
+ {
+ OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
+ }
+ }
+
+ /// <summary>
+ /// Notifies subscribers of the property change.
+ /// </summary>
+ /// <typeparam name = "TProperty">The type of the property.</typeparam>
+ /// <param name = "property">The property expression.</param>
+ public void NotifyOfPropertyChange<TProperty>(Expression<Func<TProperty>> property)
+ {
+ NotifyOfPropertyChange(property.GetMemberInfo().Name);
+ }
+
+ /// <summary>
+ /// Raises the <see cref="PropertyChanged" /> event directly.
+ /// </summary>
+ /// <param name="e">The <see cref="PropertyChangedEventArgs"/> instance containing the event data.</param>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ protected void OnPropertyChanged(PropertyChangedEventArgs e)
+ {
+ var handler = PropertyChanged;
+ if (handler != null)
+ {
+ handler(this, e);
+ }
+ }
+ }
+}