ViewModelControl.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Windows.Controls;
  7. using System.Windows.Input;
  8. using Aitex.Core.UI.MVVM;
  9. using Aitex.Core.Util;
  10. using Aitex.Core.Utilities;
  11. namespace EfemDualUI.Controls.Common
  12. {
  13. public class ViewModelControl : UserControl, INotifyPropertyChanged, IViewModelControl
  14. {
  15. public event PropertyChangedEventHandler PropertyChanged;
  16. public void SubscribeKeys(SubscriptionViewModelBase baseModel)
  17. {
  18. baseModel.SubscribeKeys(this);
  19. }
  20. public void InvokePropertyChanged()
  21. {
  22. if (PropertyChanged != null)
  23. {
  24. var ps = this.GetType().GetProperties();
  25. foreach (var p in ps)
  26. {
  27. if (!p.GetCustomAttributes(false).Any(attribute => attribute is IgnorePropertyChangeAttribute))
  28. PropertyChanged(this, new PropertyChangedEventArgs(p.Name));
  29. if (p.PropertyType == typeof(ICommand))
  30. {
  31. if (p.GetValue(this, null) is IDelegateCommand cmd)
  32. cmd.RaiseCanExecuteChanged();
  33. }
  34. }
  35. }
  36. }
  37. }
  38. }