Catel.MVVM.ViewModelBase.ViewModelBase C# (CSharp) Method

ViewModelBase() protected method

Initializes a new instance of the ViewModelBase class. This constructor allows the injection of a custom IServiceLocator.
A mapped model is not registered. A mapped model property is not found.
protected ViewModelBase ( IServiceLocator serviceLocator, bool supportIEditableObject = true, bool ignoreMultipleModelsWarning = false, bool skipViewModelAttributesInitialization = false ) : System
serviceLocator IServiceLocator The service locator to inject. If null, the will be used.
supportIEditableObject bool if set to true, the view model will natively support models that /// implement the interface.
ignoreMultipleModelsWarning bool if set to true, the warning when using multiple models is ignored.
skipViewModelAttributesInitialization bool if set to true, the initialization will be skipped and must be done manually via .
return System
        protected ViewModelBase(IServiceLocator serviceLocator, bool supportIEditableObject = true, bool ignoreMultipleModelsWarning = false,
            bool skipViewModelAttributesInitialization = false)
        {
            UniqueIdentifier = UniqueIdentifierHelper.GetUniqueIdentifier<ViewModelBase>();
            ViewModelConstructionTime = FastDateTime.Now;

            if (CatelEnvironment.IsInDesignMode)
            {
                return;
            }

            Log.Debug("Creating view model of type '{0}' with unique identifier {1}", GetType().Name, UniqueIdentifier);

            _ignoreMultipleModelsWarning = ignoreMultipleModelsWarning;

            if (serviceLocator == null)
            {
                serviceLocator = ServiceLocator.Default;
            }

#if !XAMARIN
            DependencyResolver = serviceLocator.ResolveType<IDependencyResolver>();
            _dispatcherService = DependencyResolver.Resolve<IDispatcherService>();
#endif

            // In silverlight, automatically invalidate commands when property changes
#if !WINDOWS_PHONE && !NET35
            ValidateModelsOnInitialization = true;
#endif

            ViewModelCommandManager = MVVM.ViewModelCommandManager.Create(this);
            ViewModelCommandManager.AddHandler(async (viewModel, propertyName, command, commandParameter) =>
            {
                var eventArgs = new CommandExecutedEventArgs((ICatelCommand)command, commandParameter, propertyName);

                CommandExecuted.SafeInvoke(this, eventArgs);
                await CommandExecutedAsync.SafeInvokeAsync(this, eventArgs);
            });

            InvalidateCommandsOnPropertyChanged = true;
            SupportIEditableObject = supportIEditableObject;

            // Temporarily suspend validation, will be enabled at the end of constructor again
            SuspendValidation = true;

            if (!skipViewModelAttributesInitialization)
            {
                InitializeViewModelAttributes();
            }

            ViewModelManager.RegisterViewModelInstance(this);

            object[] interestedInAttributes = GetType().GetCustomAttributesEx(typeof(InterestedInAttribute), true);
            foreach (InterestedInAttribute interestedInAttribute in interestedInAttributes)
            {
                ViewModelManager.AddInterestedViewModelInstance(interestedInAttribute.ViewModelType, this);
            }

            InitializeThrottling();

            // Enable validation again like we promised some lines of code ago
            SuspendValidation = false;

            // As a last step, enable the auditors (we don't need change notifications of previous properties, etc)
            AuditingHelper.RegisterViewModel(this);
        }
        #endregion

Same methods

ViewModelBase::ViewModelBase ( ) : System
ViewModelBase::ViewModelBase ( bool supportIEditableObject, bool ignoreMultipleModelsWarning = false, bool skipViewModelAttributesInitialization = false ) : System