コード例 #1
0
ファイル: LogicBase.cs プロジェクト: gautamsi/Catel
        /// <summary>
        /// Called when the <see cref="TargetView"/> has just been unloaded.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        /// <remarks>
        /// This method will call the <see cref="OnTargetViewUnloaded"/> which can be overriden for custom
        /// behavior. This method is required to protect from duplicate unloaded events.
        /// </remarks>
        private void OnTargetViewUnloadedInternal(object sender, EventArgs e)
        {
            if (!CanUnload)
            {
                return;
            }

            Log.Debug("Target control '{0}' is unloaded", TargetView.GetType().Name);

            var view = TargetView;

            if (view != null)
            {
                _viewManager.UnregisterView(view);
            }

            IsTargetViewLoaded            = false;
            _isFirstValidationAfterLoaded = true;

            OnTargetViewUnloaded(sender, e);

            var targetViewAsViewModelContainer = TargetView as IViewModelContainer;

            if (targetViewAsViewModelContainer != null)
            {
                ViewToViewModelMappingHelper.UninitializeViewToViewModelMappings(targetViewAsViewModelContainer);
            }

            IsUnloading = false;
        }
コード例 #2
0
ファイル: LogicBase.cs プロジェクト: gautamsi/Catel
        /// <summary>
        /// Called when the <c>DataContext</c> property of the <see cref="TargetView" /> has changed.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        public virtual void OnTargetViewDataContextChanged(object sender, DataContextChangedEventArgs e)
        {
            if (e.AreEqual)
            {
                return;
            }

            Log.Debug("DataContext of TargetView '{0}' has changed to '{1}'", TargetView.GetType().Name, ObjectToStringHelper.ToTypeString(TargetView.DataContext));

            var dataContext = TargetView.DataContext;

            if (dataContext == null)
            {
                return;
            }

            if (dataContext.IsSentinelBindingObject())
            {
                return;
            }

            if (ViewModel == dataContext)
            {
                return;
            }

            if (dataContext.GetType().IsAssignableFromEx(ViewModelType))
            {
                // Use the view model from the data context, probably set manually
                ViewModel = (IViewModel)dataContext;
            }
        }
コード例 #3
0
ファイル: LogicBase.cs プロジェクト: Lukino2000/Catel
        /// <summary>
        /// Called when the <see cref="TargetView"/> has just been loaded.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        /// <remarks>
        /// This method will call the <see cref="OnTargetViewLoaded"/> which can be overriden for custom
        /// behavior. This method is required to protect from duplicate loaded events.
        /// </remarks>
        private void OnTargetViewLoadedInternal(object sender, EventArgs e)
        {
            if (!CanLoad)
            {
                return;
            }

            Log.Debug("Target view '{0}' is loaded", TargetView.GetType().Name);

            var view = TargetView;

            if (view != null)
            {
                _viewManager.RegisterView(view);
            }

            IsTargetViewLoaded = true;

            OnTargetViewLoaded(sender, e);

            TargetView.EnsureVisualTree();

            var targetViewAsViewModelContainer = TargetView as IViewModelContainer;

            if (targetViewAsViewModelContainer != null)
            {
                ViewToViewModelMappingHelper.InitializeViewToViewModelMappings(targetViewAsViewModelContainer);
            }

            TargetView.Dispatch(() =>
            {
#pragma warning disable 4014
                // No need to await
                InitializeViewModelAsync();
#pragma warning restore 4014
            });

            IsLoading = false;
        }
コード例 #4
0
        /// <summary>
        /// Subscribes to the parent view model container.
        /// </summary>
        private void SubscribeToParentViewModelContainer()
        {
            if (!SupportParentViewModelContainers)
            {
                return;
            }

            if (HasParentViewModelContainer)
            {
                return;
            }

            _parentViewModelContainer = TargetView.FindParentViewModelContainer();
            if (_parentViewModelContainer != null)
            {
                Log.Debug("Found the parent view model container '{0}' for '{1}'", _parentViewModelContainer.GetType().Name, TargetView.GetType().Name);
            }
            else
            {
                Log.Debug("Couldn't find parent view model container");
            }

            ApiCop.UpdateRule <UnusedFeatureApiCopRule>("UserControlLogic.SupportParentViewModelContainers",
                                                        rule => rule.IncreaseCount(_parentViewModelContainer != null, TargetViewType.FullName));

            if (_parentViewModelContainer != null)
            {
                _parentViewModelContainer.ViewModelChanged += OnParentViewModelContainerViewModelChanged;

                SubscribeToParentViewModel(_parentViewModelContainer.ViewModel);
            }
        }