示例#1
0
        private void SubscribeToChanges <TView, TViewModel>(RegistredView <TView, TViewModel> view)
            where TView : class, IView
            where TViewModel : class, INotifyPropertyChanged, IActivable
        {
            var disposable = view.ViewModel.ObservePropertyChange(x => x.IsActive).Where(x => x).Subscribe((x) =>
            {
                navigationProvider.Navigate(view);
            }, err => throw err);

            if (!ActivateSubscriptions.TryGetValue(view, out var subscription))
            {
                ActivateSubscriptions.Add(view, disposable);
            }
            else
            {
                subscription.Dispose();
                ActivateSubscriptions[view] = disposable;
            }
        }
示例#2
0
        public IRegionManager RegisterView <TView, TViewModel>(
            string regionName,
            TViewModel viewModel,
            bool containsNestedRegion,
            out Guid guid,
            IRegionManager parentRegionManager = null)
            where TView : class, IView
            where TViewModel : class, INotifyPropertyChanged, IActivable
        {
            var registredView = Views.SingleOrDefault(x => x.ViewName == RegistredView <TView, TViewModel> .GetViewName(regionName, viewModel));

            if (registredView == null)
            {
                IRegionManager actualRegionManager = null;

                if (parentRegionManager != null)
                {
                    actualRegionManager = parentRegionManager;
                }
                else
                {
                    actualRegionManager = regionManagers.Single(x => x.Regions.Any(y => y.Name == regionName));
                }

                if (actualRegionManager.Regions.Count(x => x.Name == regionName) == 0)
                {
                    throw new Exception($"RegionManager does not contains region {regionName}");
                }

                var view = Application.Current?.Dispatcher?.Invoke(() =>
                {
                    return(CreateView <TView, TViewModel>(regionName, viewModel, actualRegionManager, containsNestedRegion));
                });

                Views.Add(view);

                guid = view.Guid;

                SubscribeToChanges(view);

                var regionManager = view.RegionManager;

                if (regionManager != null)
                {
                    regionManagers.Add(regionManager);
                }

                return(regionManager);
            }
            else if (registredView is RegistredView <TView, TViewModel> view)
            {
                view.ViewModel = viewModel;

                guid = view.Guid;

                SubscribeToChanges(view);

                return(view.RegionManager);
            }
            else
            {
                throw new NotImplementedException();
            }
        }