Пример #1
0
        private void InvokeOnSynchronizedActiveAwareChildren(object item, Action <IActiveAware> invocation)
        {
            var dependencyObjectView = (DependencyObject)item;

            if (dependencyObjectView == null)
            {
                return;
            }

            // We are assuming that any scoped region managers are attached directly to the view.
            var regionManager = RegionManager.GetRegionManager(dependencyObjectView);

            // If the view's RegionManager attached property is different from the region's RegionManager,
            // then the view's region manager is a scoped region manager.
            if (regionManager == null || regionManager == Region.RManager)
            {
                return;
            }

            var activeViews     = regionManager.Regions.SelectMany(e => e.ActiveViews);
            var syncActiveViews = activeViews.Where(ShouldSyncActiveState);

            foreach (var syncActiveView in syncActiveViews)
            {
                MvvmHelpers.ViewAndViewModelAction(syncActiveView, invocation);
            }
        }
Пример #2
0
        private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == NotifyCollectionChangedAction.Add)
            {
                foreach (object item in e.NewItems)
                {
                    void Invocation(IActiveAware activeAware) => activeAware.IsActive = true;

                    MvvmHelpers.ViewAndViewModelAction(item, (Action <IActiveAware>)Invocation);
                    InvokeOnSynchronizedActiveAwareChildren(item, Invocation);
                }
            }
            else if (e.Action == NotifyCollectionChangedAction.Remove)
            {
                foreach (object item in e.OldItems)
                {
                    void Invocation(IActiveAware activeAware) => activeAware.IsActive = false;

                    MvvmHelpers.ViewAndViewModelAction(item, (Action <IActiveAware>)Invocation);
                    InvokeOnSynchronizedActiveAwareChildren(item, Invocation);
                }
            }

            // May need to handle other action values (reset, replace). Currently the ViewsCollection class does not raise CollectionChanged with these values.
        }
Пример #3
0
        /// <summary>
        /// Configure <see cref="IDialogWindow"/> content.
        /// </summary>
        /// <param name="dialogName">The name of the dialog to show.</param>
        /// <param name="window">The hosting window.</param>
        /// <param name="parameters">The parameters to pass to the dialog.</param>
        protected virtual void ConfigureDialogWindowContent(string dialogName, IDialogWindow window, IDialogParameters parameters)
        {
            var content = _containerExtension.Resolve <object>(dialogName);

            if (content is not FrameworkElement dialogContent)
            {
                throw new NullReferenceException("A dialog's content must be a FrameworkElement");
            }

            MvvmHelpers.AutowireViewModel(dialogContent);

            if (dialogContent.DataContext is not IDialogAware viewModel)
            {
                throw new NullReferenceException("A dialog's ViewModel must implement the IDialogAware interface");
            }
            ConfigureDialogWindowProperties(window, dialogContent, viewModel);
            MvvmHelpers.ViewAndViewModelAction <IDialogAware>(viewModel, d => d.OnDialogOpened(parameters));
        }