From 439ee2d80eab039c2dee00f697d2d814ec67247e Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Wed, 22 Aug 2018 18:33:29 +0300 Subject: Added IsFree to base ViewModel. Implemented IsFree on HardwareVersions & ColorLab modules. --- Software/Visual_Studio/Tango.SharedUI/ViewModel.cs | 52 +++++++++------------- 1 file changed, 22 insertions(+), 30 deletions(-) (limited to 'Software/Visual_Studio/Tango.SharedUI/ViewModel.cs') diff --git a/Software/Visual_Studio/Tango.SharedUI/ViewModel.cs b/Software/Visual_Studio/Tango.SharedUI/ViewModel.cs index 7d215cd06..d4f26c79d 100644 --- a/Software/Visual_Studio/Tango.SharedUI/ViewModel.cs +++ b/Software/Visual_Studio/Tango.SharedUI/ViewModel.cs @@ -23,6 +23,7 @@ namespace Tango.SharedUI public abstract class ViewModel : ExtendedObject, INotifyDataErrorInfo { private List> _currentErrors = new List>(); //Holds the current validation errors. + private bool _isFreeSet; private bool _hasErrors; /// @@ -34,6 +35,16 @@ namespace Tango.SharedUI set { _hasErrors = value; RaisePropertyChangedAuto(); } } + private bool _isFree; + /// + /// Gets or sets a value indicating whether this view model is free to perform actions. + /// + public bool IsFree + { + get { return _isFree; } + set { _isFree = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); } + } + private ObservableCollection _validationErrors; /// /// Gets or sets the validation errors. @@ -49,6 +60,14 @@ namespace Tango.SharedUI /// public event EventHandler ErrorsChanged; + /// + /// Initializes a new instance of the class. + /// + public ViewModel() + { + IsFree = true; + } + /// /// Gets the validation errors for a specified property or for the entire entity. /// @@ -160,42 +179,15 @@ namespace Tango.SharedUI /// public T View { get; set; } - - /// - /// Initializes a new instance of the class. - /// - /// The view. - public ViewModel(T view) - { - View = view; - View.ViewAttached += (x, e) => - { - View = (T)e; - OnViewAttached(); - }; - } - /// /// Initializes a new instance of the class. /// - /// The view. - /// if set to true waits for the view to be valid before registering for the event. - public ViewModel(T view, bool delayed) + public ViewModel() : base() { - Task.Factory.StartNew(() => - { - while (view == null) - { - Thread.Sleep(10); - } - }).ContinueWith((c) => + TangoIOC.Default.GetInstanceWhenAvailable((view) => { View = view; - View.ViewAttached += (x, e) => - { - View = (T)e; - OnViewAttached(); - }; + OnViewAttached(); }); } -- cgit v1.3.1