diff options
| author | Roy <roy.mail.net@gmail.com> | 2017-12-06 10:11:45 +0200 |
|---|---|---|
| committer | Roy <roy.mail.net@gmail.com> | 2017-12-06 10:11:45 +0200 |
| commit | 3e665934f3f01b2cdd3de3fbc2c03ae27ac5740e (patch) | |
| tree | def622f54dff1dfc0820ed8fdd96edad98c05ec3 /Software/Visual_Studio/Tango.Core/ExtendedObject.cs | |
| parent | 3689238cb9ca77cbd7fa34dbd15003af87266e36 (diff) | |
| download | Tango-3e665934f3f01b2cdd3de3fbc2c03ae27ac5740e.tar.gz Tango-3e665934f3f01b2cdd3de3fbc2c03ae27ac5740e.zip | |
Moved ExtendedObject & RelayCommand to Core.
CodeGeneration EntityCodeFile working + cycle reference!
Diffstat (limited to 'Software/Visual_Studio/Tango.Core/ExtendedObject.cs')
| -rw-r--r-- | Software/Visual_Studio/Tango.Core/ExtendedObject.cs | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.Core/ExtendedObject.cs b/Software/Visual_Studio/Tango.Core/ExtendedObject.cs new file mode 100644 index 000000000..84a73bf7c --- /dev/null +++ b/Software/Visual_Studio/Tango.Core/ExtendedObject.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using Tango.Core.Commands; + +namespace Tango.Core +{ + /// <summary> + /// Represents an extension to the standard core object with support for property and relay commands changed event. + /// </summary> + /// <seealso cref="System.ComponentModel.INotifyPropertyChanged" /> + [Serializable] + public class ExtendedObject : INotifyPropertyChanged + { + /// <summary> + /// Occurs when a property has changed. + /// </summary> + [field: NonSerialized] + public event PropertyChangedEventHandler PropertyChanged; + + /// <summary> + /// Raises the property changed event. + /// </summary> + /// <param name="propName">Name of the property.</param> + protected virtual void RaisePropertyChanged(String propName) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName)); + } + + /// <summary> + /// Raises all relay commands CanExecute methods in the current instance. + /// </summary> + protected virtual void InvalidateRelayCommands() + { + Application.Current.Dispatcher.BeginInvoke(new Action(() => + { + foreach (var prop in this.GetType().GetProperties().Where(x => x.PropertyType == typeof(RelayCommand))) + { + var value = prop.GetValue(this) as RelayCommand; + + if (value != null) + { + value.RaiseCanExecuteChanged(); + } + } + })); + } + + /// <summary> + /// Invokes the specified action on the UI Thread. + /// </summary> + /// <param name="action">The action.</param> + protected virtual void InvokeUI(Action action) + { + Application.Current.Dispatcher.BeginInvoke(action); + } + + /// <summary> + /// Invokes the specified action on the UI Thread. + /// </summary> + /// <param name="action">The action.</param> + protected virtual void InvokeUINow(Action action) + { + Application.Current.Dispatcher.Invoke(action); + } + } +} |
