Esempio n. 1
0
 /// <summary>
 /// Push property changed updates to the client.
 /// </summary>
 public void PushUpdates()
 {
     if (ChangedProperties.Any())
     {
         RequestPushUpdates?.Invoke(this, null);
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Push property changed updates to the client.  It accepts a boolean to force the request be sent to the VMController
 /// even when there is no changed properties in this view model.  The intent is to allow a way for this view model to
 /// push changes in other view models that share the same VMController.
 /// This method also returns a boolean just so it can support fluent chaining.
 /// </summary>
 /// <param name="force">Always send push update request.</param>
 /// <returns>True, just so it returns a value.</returns>
 public virtual bool PushUpdates(bool force)
 {
     if (ChangedProperties.Any() || force)
     {
         RequestPushUpdates?.Invoke(this, null);
     }
     return(true);
 }
Esempio n. 3
0
        /// <summary>
        /// Constructor to create a wrapper for a view model that doesn't inherit from BaseVM.
        /// </summary>
        /// <param name="vm">View model instance.</param>
        public BaseVM(INotifyPropertyChanged vm) : base()
        {
            _vmInstance         = vm;
            vm.PropertyChanged += OnPropertyChanged;
            _changedProperties  = _propertyDictionaries.Dequeue();

            if (vm is IDisposable)
            {
                Disposed += (sender, e) =>
                {
                    vm.PropertyChanged -= OnPropertyChanged;
                    (vm as IDisposable).Dispose();
                }
            }
            ;

            if (vm is IPushUpdates)
            {
                (vm as IPushUpdates).RequestPushUpdates += (sender, e) => RequestPushUpdates?.Invoke(this, e);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Constructor to create a wrapper for a view model that doesn't inherit from BaseVM.
        /// </summary>
        /// <param name="vm">View model instance.</param>
        internal BaseVM(INotifyPropertyChanged vm) : base()
        {
            _vmInstance         = vm;
            vm.PropertyChanged += OnPropertyChanged;
            _changedProperties  = _propertyDictionaries.Dequeue();

            if (vm is IReactiveProperties && (vm as IReactiveProperties).RuntimeProperties != null)
            {
                var runtimeProperties = (vm as IReactiveProperties).RuntimeProperties.Where(prop => !string.IsNullOrWhiteSpace(prop.Name)).ToList();
                runtimeProperties.ForEach(prop =>
                {
                    prop.PropertyChanged += OnPropertyChanged;
                    RuntimeProperties.Add(prop);
                    Set(prop, prop.Name);
                });
                Disposed += (sender, e) => runtimeProperties.ForEach(prop => prop.PropertyChanged -= OnPropertyChanged);
                IgnoredProperties.Add(nameof(IReactiveProperties.RuntimeProperties));
            }

            if (vm is IPushUpdates)
            {
                (vm as IPushUpdates).RequestPushUpdates += (sender, e) => RequestPushUpdates?.Invoke(this, e);
            }

            if (vm is IDisposable)
            {
                Disposed += (sender, e) =>
                {
                    vm.PropertyChanged -= OnPropertyChanged;
                    (vm as IDisposable).Dispose();
                }
            }
            ;

            if (vm is IBaseVMAccessor)
            {
                (vm as IBaseVMAccessor).OnInitialized?.Invoke(this);
            }
        }